I have tried to use the following code, which I found in a previous SO question, to upload a generated .php file to my shared server via FTP.
I am using Excel 2016 on Windows 10, and trying to upload to a server with 1and1.
Public Sub FtpSend()
Dim vPath As String
Dim vFile As String
Dim vFTPServ As String
Dim lInt_FreeFile01 As Integer
vPath = Environ("USERPROFILE") & "\Documents\UploadFiles\"
vFile = "rd1.php"
vFTPServ = "domain-name.co.uk"
lInt_FreeFile01 = FreeFile
'Mounting file command for ftp.exe
Open vPath & "\FtpComm.txt" For Output As #lInt_FreeFile01
Print #lInt_FreeFile01, "domain-name.co.uk"
Print #lInt_FreeFile01, "username"
Print #lInt_FreeFile01, "password"
Print #lInt_FreeFile01, "/test/"
Print #lInt_FreeFile01, "ascii"
Print #lInt_FreeFile01, "send " & Environ("USERPROFILE") & "\Documents\UploadFiles\" & "rd1.php"
Print #lInt_FreeFile01, "bye"
Close #lInt_FreeFile01
Shell "ftp -n -i -g -s:" & vPath & "FtpComm.txt " & vFTPServ, vbNormalNoFocus
SetAttr vPath & "FtpComm.txt", vbNormal
Kill vPath & "\FtpComm.txt"
End Sub
When I run the macro, there is no feedback as to what has happened, but the file has not been transferred into the /test/ directory on the server. I've tried a number of permutations, but I can't get it to work.
Any advice on how I can get this to work?
On another note, I also tried the code here, but couldn't get this to work either...
I have previously used FileZilla to transfer files via FTP, but this Excel workbook is going to be handed out to a number of team members and the ability to upload using Excel VBA code is an important part of streamlining the workflow.