FTP Upload/Download

hawkeye
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
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
0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions