Download files from ftp

marcelvos1
Member Posts: 6
Hi all,
I try to download files from a ftp server within NAV, but no files are downloaded to my computer. I have try the batch file directly from my computer and its still working. The ftpfile.bat is still created when I run this script in NAV.
I read the forum but I found no sollution for this.
Please help me. Thanks.
Code:
FileName := ENVIRON('TEMP') +'\ftpfile.bat';
TextFile.CREATE(FileName);
TextFile.WRITEMODE(TRUE);
TextFile.TEXTMODE(TRUE);
TextFile.WRITE('@ECHO OFF');
TextFile.WRITE('CD ' + ENVIRON('TEMP'));
TextFile.WRITE(':retry_del2');
TextFile.WRITE('DEL "*.csv" > NUL');
TextFile.WRITE('if exist "*.csv" goto retry_del2');
TextFile.WRITE('> script.ftp ECHO open ' + '[ftp server]');
TextFile.WRITE('>>script.ftp ECHO USER ' + '[user]');
TextFile.WRITE('>>script.ftp ECHO ' + '[password]');
TextFile.WRITE('>>script.ftp ECHO cd /' + '[folder]');
TextFile.WRITE('>>script.ftp ECHO bin');
TextFile.WRITE('>>script.ftp ECHO mget *.csv');
TextFile.WRITE('>>script.ftp ECHO Bye');
TextFile.WRITE('FTP -i -n -s:script.ftp ' + '[ftp server]');
TextFile.WRITE('TYPE NUL >script.ftp');
TextFile.WRITE('DEL script.ftp');
TextFile.WRITE(':retry_del');
TextFile.WRITE('DEL "' + FileName + '" > NUL');
TextFile.WRITE('if exist "' + FileName + '" goto retry_del');
TextFile.CLOSE;
IF ISCLEAR(lAutWshShell) THEN
CREATE(lAutWshShell);
lBlnWaitOnReturn := TRUE;
lIntWindowType := 0;
lAutWshShell.Run(FileName, lIntWindowType, lBlnWaitOnReturn);
CLEAR(lAutWshShell);
I try to download files from a ftp server within NAV, but no files are downloaded to my computer. I have try the batch file directly from my computer and its still working. The ftpfile.bat is still created when I run this script in NAV.
I read the forum but I found no sollution for this.
Please help me. Thanks.
Code:
FileName := ENVIRON('TEMP') +'\ftpfile.bat';
TextFile.CREATE(FileName);
TextFile.WRITEMODE(TRUE);
TextFile.TEXTMODE(TRUE);
TextFile.WRITE('@ECHO OFF');
TextFile.WRITE('CD ' + ENVIRON('TEMP'));
TextFile.WRITE(':retry_del2');
TextFile.WRITE('DEL "*.csv" > NUL');
TextFile.WRITE('if exist "*.csv" goto retry_del2');
TextFile.WRITE('> script.ftp ECHO open ' + '[ftp server]');
TextFile.WRITE('>>script.ftp ECHO USER ' + '[user]');
TextFile.WRITE('>>script.ftp ECHO ' + '[password]');
TextFile.WRITE('>>script.ftp ECHO cd /' + '[folder]');
TextFile.WRITE('>>script.ftp ECHO bin');
TextFile.WRITE('>>script.ftp ECHO mget *.csv');
TextFile.WRITE('>>script.ftp ECHO Bye');
TextFile.WRITE('FTP -i -n -s:script.ftp ' + '[ftp server]');
TextFile.WRITE('TYPE NUL >script.ftp');
TextFile.WRITE('DEL script.ftp');
TextFile.WRITE(':retry_del');
TextFile.WRITE('DEL "' + FileName + '" > NUL');
TextFile.WRITE('if exist "' + FileName + '" goto retry_del');
TextFile.CLOSE;
IF ISCLEAR(lAutWshShell) THEN
CREATE(lAutWshShell);
lBlnWaitOnReturn := TRUE;
lIntWindowType := 0;
lAutWshShell.Run(FileName, lIntWindowType, lBlnWaitOnReturn);
CLEAR(lAutWshShell);
0
Comments
-
Hi,
I just paste my working code (with PUT against GET) - maybe this will help.
I Don't know if this is the best solution, but it works for me - from Nav.CmdFile.WRITEMODE(TRUE); CmdFile.TEXTMODE(TRUE); CmdFile.QUERYREPLACE(TRUE); CmdFile.CREATE(setup."Ftp - tmp folder" + '\Cmd.txt'); CmdFile.WRITE('USER ' + UserVariable + ' ' + PassVariable); CmdFile.WRITE('cd ' + setup."ftp path"); CmdFile.WRITE('put ' + setup."ftp file"); CmdFile.WRITE('bye'); CmdFile.CLOSE; BatchFile.WRITEMODE(TRUE); BatchFile.TEXTMODE(TRUE); BatchFile.QUERYREPLACE(TRUE); BatchFile.CREATE(setup."Ftp - tmp folder" + '\FtpBatch.bat'); BatchFile.WRITE('ftp -n -s:Cmd.txt ' + setup."ftp Host"); BatchFile.CLOSE; CREATE(WScript); WScript.Exec(setup."Ftp - tmp folder" + '\FtpBatch.bat'); CLEAR(WScript);
setup."ftp Host" = Ip exmp. 101.101.101.1010 -
I have used http://www.ncftp.com/ncftp/ with success, together with a batch-file like:
"c:\Program files\NcFTP\ncftpget.exe" -u <username> -p <password> ftp.site.com C:\dir\file.ext
No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)0 -
I have a lot of fun with AutoFTP software. You can schedule an Upload or a Download at any interval.
NIEM THAI0 -
Hi all,
Thanks for your input. I found the problem. The problem was that there was no valid location to store the files when I run the script with NAV.
I add this line of code in my script and its working.
Code:
FileName := ENVIRON('TEMP') +'\ftpfile.bat';
TextFile.CREATE(FileName);
TextFile.WRITEMODE(TRUE);
TextFile.TEXTMODE(TRUE);
TextFile.WRITE('@ECHO OFF');
TextFile.WRITE('CD ' + ENVIRON('TEMP'));
TextFile.WRITE(':retry_del2');
TextFile.WRITE('DEL "*.csv" > NUL');
TextFile.WRITE('if exist "*.csv" goto retry_del2');
TextFile.WRITE('> script.ftp ECHO open ' + '[ftp server]');
TextFile.WRITE('>>script.ftp ECHO USER ' + '[user]');
TextFile.WRITE('>>script.ftp ECHO ' + '[password]');
TextFile.WRITE('>>script.ftp ECHO cd /' + '[folder]');
TextFile.WRITE('>>script.ftp ECHO lcd ' + ENVIRON('TEMP'));
TextFile.WRITE('>>script.ftp ECHO bin');
TextFile.WRITE('>>script.ftp ECHO mget *.csv');
TextFile.WRITE('>>script.ftp ECHO Bye');
TextFile.WRITE('FTP -i -n -s:script.ftp ' + '[ftp server]');
TextFile.WRITE('TYPE NUL >script.ftp');
TextFile.WRITE('DEL script.ftp');
TextFile.WRITE(':retry_del');
TextFile.WRITE('DEL "' + FileName + '" > NUL');
TextFile.WRITE('if exist "' + FileName + '" goto retry_del');
TextFile.CLOSE;
IF ISCLEAR(lAutWshShell) THEN
CREATE(lAutWshShell);
lBlnWaitOnReturn := TRUE;
lIntWindowType := 0;
lAutWshShell.Run(FileName, lIntWindowType, lBlnWaitOnReturn);
CLEAR(lAutWshShell);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