SFTP for NAV 2009

ajayjain
Member Posts: 119
Hi,
I was using FTP on classic client which was working fine
Now it has been changed to SFTP
can you please tell me how can I use SFTP
WinSCP does not work on classic client 2009
Any other standard/free api/automation ?
Thanks
I was using FTP on classic client which was working fine
Now it has been changed to SFTP
can you please tell me how can I use SFTP
WinSCP does not work on classic client 2009
Any other standard/free api/automation ?
Thanks
Ajay Jain
UK
UK
0
Answers
-
Well, I´ve done sftp implementation for some customer in the past I recall I used winscp dotnet variable and adapted a piece of code, I hope this helps. Sftp key can be found when logging from windows client, you can store it in customer card or like this. Dotnet variables can be found in winscp website, they need to go to service folder so they distribute automatically
About classic client, the only way I see is to call a exposed function from NAV WS so this way it will run RTC.
:
PROCEDURE SFTP@1000000026(Operation@1000000000 : 'Upload,List,Delete';pLogin@1000000010 : Text[50];pPassword@1000000009 : Text[50];pLocalFile@1000000008 : Text[250];pRemoteFile@1000000007 : Text[250];pLogFile@1000000004 : Text[250];pFTPDirectory@1000000011 : Text[250]) vSuccess : Boolean;
VAR
WinSCPSessionOptions@1000000006 : DotNet "'WinSCPnet, Version=1.3.7.7601, Culture=neutral, PublicKeyToken=2271ec4a3c56d0bf'.WinSCP.SessionOptions";
WinSCPSesh@1000000005 : DotNet "'WinSCPnet, Version=1.3.7.7601, Culture=neutral, PublicKeyToken=2271ec4a3c56d0bf'.WinSCP.Session";
WinSCPTransferOptions@1000000003 : DotNet "'WinSCPnet, Version=1.3.7.7601, Culture=neutral, PublicKeyToken=2271ec4a3c56d0bf'.WinSCP.TransferOptions";
WinSCPTransferResults@1000000001 : DotNet "'WinSCPnet, Version=1.3.7.7601, Culture=neutral, PublicKeyToken=2271ec4a3c56d0bf'.WinSCP.TransferOperationResult";
vHost@1000000002 : Text;
vPort@1000000012 : Integer;
vRemoteFile@1000000013 : Text;
BEGIN
vSuccess:=FALSE;
gsFTPError:=FALSE;
WinSCPSessionOptions := WinSCPSessionOptions.SessionOptions;
vHost:=COPYSTR(gHost,7,STRLEN(gHost)); //remove port. we start after ftp://
EVALUATE(vPort,COPYSTR(vHost,STRPOS(vHost,':')+1,STRLEN(vHost))); //copy port
vHost:=COPYSTR(vHost,1,STRPOS(vHost,':')-1); //copy only until port
WinSCPSessionOptions.HostName(vHost);
WinSCPSessionOptions.PortNumber(vPort);
WinSCPSessionOptions.UserName(gLogin);
WinSCPSessionOptions.Password(gPassword);
//amend remote file
//full string to amend: 'ftp://XXX.XXX.XX.XX:22/uploads/Inventory.csv'
vRemoteFile:=COPYSTR(pRemoteFile,STRPOS(pRemoteFile,':')+1,STRLEN(pRemoteFile)); //copy till first :
vRemoteFile:=COPYSTR(vRemoteFile,STRPOS(vRemoteFile,':')+3,STRLEN(vRemoteFile));
//run winscp windows client and you will find the following key there
WinSCPSessionOptions.SshHostKeyFingerprint(sFTPKey);
WinSCPSesh:=WinSCPSesh.Session;
WinSCPSesh.Open(WinSCPSessionOptions);
WinSCPTransferOptions := WinSCPTransferOptions.TransferOptions();
WinSCPTransferOptions.TransferMode:=0;
CASE Operation OF
Operation::Upload: BEGIN
//premotefile needs to be cut the string
WinSCPTransferResults:=WinSCPSesh.PutFiles(pLocalFile,vRemoteFile,FALSE,WinSCPTransferOptions);
// WinSCPTransferResults:=WinSCPSesh.GetFiles(pRemoteFile,pLocalFile,FALSE,WinSCPTransferOptions);
// WinSCPTransferResults.Check();
vSuccess:=WinSCPTransferResults.IsSuccess();
IF vSuccess=FALSE THEN BEGIN
WriteToErrorLog(pLogFile,FORMAT(WinSCPTransferResults.ToString(),1024));
gsFTPError:=TRUE;
END;
END;
Operation::List:
BEGIN
vSuccess:=WinSCPSesh.FileExists(vRemoteFile);
// IF vSuccess THEN
// WinSCPSesh.RemoveFiles(pRemoteFile);
END;
Operation::Delete: BEGIN
IF WinSCPSesh.FileExists(vRemoteFile) THEN BEGIN
WinSCPSesh.RemoveFiles(vRemoteFile);
WinSCPTransferResults:=WinSCPSesh.GetFiles(vRemoteFile,TEMPORARYPATH+'tmpfile.tmp',FALSE,WinSCPTransferOptions);
// WinSCPTransferResults.Check();
vSuccess:=WinSCPTransferResults.IsSuccess();
IF vSuccess=FALSE THEN
vSuccess:=TRUE; //if it cant find means the file is deleted properly
END
ELSE
vSuccess:=TRUE;
END;
END;
END;
PROCEDURE SetSFTP@1100270000(psFTP@1100270000 : Boolean;pSftpKey@1100270001 : Text);
BEGIN
gsFTP:=psFTP;
sFTPKey:=pSftpKey;
END;
More details:
https://community.dynamics.com/nav/b/researchdesigndevelop/archive/2017/10/31/file-upload-sftp
https://winscp.net/eng/docs/library#vbnet0 -
Thanks very much treff
I have done in classic client, it works in the same way as used to be
you can write the dos comments in batch/txt file and execute
Thanks
AjayAjay Jain
UK0 -
Hi Ajay,
Can you please share some details about it.
SFTP through batch file.
Thanks in advance0 -
Hi Please Help Me
I added the dll ( WinSCP for SFTP) to windows. I created a new automation. But the methods of this automaition are not listed. Don't see metod list.0 -
Thanks
Blog - rockwithnav.wordpress.com/
Twitter - https://twitter.com/RockwithNav
Facebook - https://facebook.com/rockwithnav/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