ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to save the Current Excel file to FTP server (https://www.excelbanter.com/excel-programming/295609-how-save-current-excel-file-ftp-server.html)

Patrick[_9_]

How to save the Current Excel file to FTP server
 
Dear Expert,
How to save the Current Excel file to FTP server (must use VBA Coding)

I have tried many ways but it seem cannot work through.....

Tried #1 ....
ActiveWorkbook.SaveAs /Reports/" &
FileName
Error Message come out


Tried #2 ....
Open FilePath & "ftp.bat" For Output As #1
Print #1, "open " & "61.38.xxx.xxx"
Print #1, "username"
Print #1, "password"
Print #1, "put"
Print #1, """" & FileNameSaved & """"
Print #1, "/Reports/" & FileName
Print #1, "close"
Print #1, "quit"
Close #1

RetVal = Shell("ftp.exe -s:""" & FilePath & "ftp.bat""", vbHide)
Error Message come out too, and do not know when is finish upload
process


Tried #3 ....
I used "wininet.dll" via API

Dim hConnection As Long, hOpen As Long, sOrgPath As String
'// open an internet connection
hOpen = InternetOpen("Upload Excel To Ftp", _
&H0, _
vbNullString, _
vbNullString, _
0)
'// connect to the FTP server
hConnection = InternetConnect(hOpen, _
"61.38.xxx.xxx", _
21, _
"username", _
"password", _
1, _
0, _
0)
'// set the current directory to 'root/reports'
Ret = FtpSetCurrentDirectory(hConnection, "Reports")
'// upload the file
Ret = FtpPutFile(hConnection, FileNameSaved, FileName, &H0, 0)

'// close the FTP connection
InternetCloseHandle hConnection
'// close the internet connection
InternetCloseHandle hOpen

Error on the major instruction, i.e. "Ret = FtpPutFile(hConnection,
FileNameSaved, FileName, &H0, 0)"


Cannot Try #4 ....
I heard, can use an ActiveX control (Inet.ocx), but I cannot find it
on the VBA project reference, even the userform control add also cannot find
this component.

Appreciate on advise

Patrick












All times are GMT +1. The time now is 06:30 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com