Zubair2icy
New Member
- Joined
- Nov 27, 2022
- Messages
- 1
- Office Version
- 365
- Platform
- MacOS
I have an excel VBA code to upload file to FTP server which works on windows, but I need it to work on Mac. I am using MS365. See the code below:
Sub fileToFTP()
Set FSO = CreateObject("scripting.filesystemobject")
'set the pathe and file name of the script to be run
F = "C:\temp\FTPScript.txt"
'Create the ftpscript to be run
Open F For Output As #1
Print #1, "open 111.111.111.111" 'replace ftp.server with the server address
Print #1, "myusername" 'login id here
Print #1, "mypass" 'login password here
Print #1, "pasv" ' passive mode ftp if needed
'change remote directories if needed
'Print #1, "cd " & " /dir" 'Directory of file location
'Print #1, "cd " & " subdir" 'Sub-Directory of file location
Print #1, "ascii"
Print #1, "prompt"
'Put the file from the host and save it to the specified directory and filename
Print #1, "put " & VREDET; """C:\temp\yourFile.xlsx"""; ""
'additional files if needed
'Print #1, "put " & VREDET; """C:\file2.csv"""; ""
'Print #1, "put " & VREDET; """C:\file3.csv"""; ""
Print #1, "disconnect" 'disconnect the session
Print #1, "bye"
Print #1, "exit"
Close #1
'Now for the command to upload to the ftpsite and log it to a text file
' the trick is to use the standard command shell which allows logging
Set FSO = Nothing
Shell "cmd /c C:\WINDOWS\system32\ftp.exe -i -s:C:\temp\FTPScript.txt > c:\temp\ftpuploadlog.txt", vbHide
End Sub
Sub fileToFTP()
Set FSO = CreateObject("scripting.filesystemobject")
'set the pathe and file name of the script to be run
F = "C:\temp\FTPScript.txt"
'Create the ftpscript to be run
Open F For Output As #1
Print #1, "open 111.111.111.111" 'replace ftp.server with the server address
Print #1, "myusername" 'login id here
Print #1, "mypass" 'login password here
Print #1, "pasv" ' passive mode ftp if needed
'change remote directories if needed
'Print #1, "cd " & " /dir" 'Directory of file location
'Print #1, "cd " & " subdir" 'Sub-Directory of file location
Print #1, "ascii"
Print #1, "prompt"
'Put the file from the host and save it to the specified directory and filename
Print #1, "put " & VREDET; """C:\temp\yourFile.xlsx"""; ""
'additional files if needed
'Print #1, "put " & VREDET; """C:\file2.csv"""; ""
'Print #1, "put " & VREDET; """C:\file3.csv"""; ""
Print #1, "disconnect" 'disconnect the session
Print #1, "bye"
Print #1, "exit"
Close #1
'Now for the command to upload to the ftpsite and log it to a text file
' the trick is to use the standard command shell which allows logging
Set FSO = Nothing
Shell "cmd /c C:\WINDOWS\system32\ftp.exe -i -s:C:\temp\FTPScript.txt > c:\temp\ftpuploadlog.txt", vbHide
End Sub