Thursday, 11 February 2016

How to Execute FTP Commands With VBAIn Feburary 2016 11,

In Feburary 2016 11,
Create the FTP command file with a list of commands that the FTP client will execute. The following VBA code fragment creates such a file:Dim ftpFileHandle As IntegerftpFileHandle = FreeFileOpen 'ftpCommand.txt' For Output As #ftpFileHandlePrint #ftpFileHandle, 'open ftpserver.com'Print #ftpFileHandle, 'userid'Print #ftpFileHandle, 'password'Print #ftpFileHandle, 'send localfile.xls'Print #ftpFileHandle, 'recv remotefile.doc'Print #ftpFileHandle, 'bye'Close #ftpFileHandleReplace 'ftpserver.com' with the name of the FTP server, 'userid' with the name of your account in that server and 'password' with your password. The sample code uploads a spreadsheet contained in a file named 'localfile.xls' and downloads a document contained in a file named 'remotefile.doc.' You can use any of the commands from the 'List of FTP Commands' on the NSF Tools website before closing the session with 'bye.'
Create a batch, or executable script, file that invokes the FTP client to have it execute the FTP command file. The following VBA code fragment creates such a file:Dim batFileHandle As IntegerbatFileHandle = FreeFileOpen 'doFtp.bat' For Output As #batFileHandlePrint #batFileHandle, 'ftp -s:ftpCommand.txt'Close #batFileHandle
Execute the batch file by including the following line in your VBA code:Shell ('doFtp.bat'), vbHide '', vbMinimizedNoFocusNote that the line contains two single quotes, without any character between them, immediately before the second comma. Your VBA program will invoke the batch file that, in turn, will invoke the FTP client and have it execute the sequence of commands from Step 1.
In Feburary 2016 11,

No comments:

Post a Comment