Options

FTP Upload/Download

hawkeyehawkeye Member Posts: 51
Hi all

I used a long time in here to find a good way of exporting/importing to/from FTP using no extra external programs.

There are many posts in here about the subject, but I had a hard time figuring out the best solution. I didn´t find a post that was spot on to my needs.

Heres my solution.
I made a setup table to hold all the variables - FTPSetup.
I create two files each time, holding the necessary information - CmdFile and BatchFile.

You can modify it with "mget"/"mput" - "*.txt" and "del" to handle more than one file and to delete the file from the destination.

Instead of my "sleep" you can also make a "if file exists then......"

You can also make a rename/move of the file to handle the archiving of processed files. I didn´t do that in the example here, because it was not relevant for me.

PUT:
CMDFile.CREATE(FTPSetup."Temp Path" + 'CMDput.txt');
CMDFile.WRITEMODE(TRUE);
CMDFile.TEXTMODE(TRUE);
CMDFile.WRITE(FTPSetup."FTP User");
CMDFile.WRITE(FTPSetup."FTP Password");
IF FTPSetup."FTP Folder export" <> '' THEN
CMDFile.WRITE('cd ' + FTPSetup."FTP Folder export");
CMDFile.WRITE('put ' + FTPSetup."Export File Path" + FTPSetup."Filename Export");
CMDFile.WRITE('bye');
CMDFile.CLOSE;

BatchFile.WRITEMODE(TRUE);
BatchFile.TEXTMODE(TRUE);
BatchFile.CREATE(FTPSetup."Temp Path" +'FtpBatchput.bat');
BatchFile.WRITE('ftp -i -s:'+FTPSetup."Temp Path" + 'CMDput.txt ' + FTPSetup."FTP address");
BatchFile.CLOSE;

SLEEP(1000);

SHELL(FTPSetup."Temp Path" + 'FtpBatchput.bat');

GET:
CmdFile.CREATE(FTPSetup."Temp Path" + 'CMDget.txt');
CmdFile.WRITEMODE(TRUE);
CmdFile.TEXTMODE(TRUE);
CmdFile.WRITE(FTPSetup."FTP User");
CmdFile.WRITE(FTPSetup."FTP Password");
IF FTPSetup."FTP Folder Import" <> '' THEN
CmdFile.WRITE('cd ' + FTPSetup."FTP Folder Import");
CmdFile.WRITE('get ' + FTPSetup."Filname Import");
CmdFile.WRITE('bye');
CmdFile.CLOSE;

BatchFile.WRITEMODE(TRUE);
BatchFile.TEXTMODE(TRUE);
BatchFile.CREATE(FTPSetup."Temp Path" + 'FtpBatchget.bat');
BatchFile.WRITE('CD ' + FTPSetup."Import File Path");
BatchFile.WRITE('ftp -i -s:' + FTPSetup."Temp Path" + 'CMDget.txt ' + FTPSetup."FTP address");
BatchFile.CLOSE;

SLEEP(1000);

SHELL(FTPSetup."Temp Path" + 'FtpBatchget.bat');

I hope this was helpfull

BR

Hawkeye
Sign In or Register to comment.