FTP upload with DotNet

ivarsk
Member Posts: 12
Hi, everyone.
I have created an FTP upload function from within NAV using .NET, so that no external libs are needed for that.
Gladly sharing this with you (not optimized or anything, but works):
Now a question - I can't get my head around this:
The
FTPRequest.Method := 'STOR';
was my lucky guess, and every code sample I've seen actually says:
FTPRequest.Method := WebRequestMethods.Ftp.UploadFile;
As far as I understand, WebRequestMethods.Ftp is a .NET enumeration that in this case corresponds Strings.
How to use these enumerations appropriately?
Disclaimer: This is my first encounter with NAV+.NET
I have created an FTP upload function from within NAV using .NET, so that no external libs are needed for that.
Gladly sharing this with you (not optimized or anything, but works):
URL := 'ftp://remote_server/remote_folder/testfile.txt'; FTPRequest := WebRequest.Create(URL); Credentials := Credentials.NetworkCredential('some_login', 'some_password'); FTPRequest.Credentials := Credentials; FTPRequest.KeepAlive := false; FTPRequest.UseBinary := true; FTPRequest.Method := 'STOR'; FTPRequest.UsePassive := true; FileStream := FileA.OpenRead('c:\testfile.txt'); FTPRequest.GetRequestStream.Write(FileA.ReadAllBytes('c:\testfile.txt'), 0, FileStream.Length); --- WebRequest DotNet 'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Net.WebRequest FTPRequest DotNet 'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Net.FtpWebRequest Credentials DotNet 'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Net.NetworkCredential FileStream DotNet 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.IO.FileStream FileA DotNet 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.IO.File URL Text 250
Now a question - I can't get my head around this:
The
FTPRequest.Method := 'STOR';
was my lucky guess, and every code sample I've seen actually says:
FTPRequest.Method := WebRequestMethods.Ftp.UploadFile;
As far as I understand, WebRequestMethods.Ftp is a .NET enumeration that in this case corresponds Strings.
How to use these enumerations appropriately?
Disclaimer: This is my first encounter with NAV+.NET

0
Comments
-
=D> Thank you, exactly what I was looking for.0
-
Hello Ivarsk,
I wonder if you ever got this working with downloading by ftp?
Thanks to your sharing I was able to get the upload working, but I can't figure out the syntax to make it download.
My attempts shown here:
viewtopic.php?f=32&t=58060
Would really appreciate any advice. This is absolutely a first attempt with anything dotnet for me.
Bruce Anderson0 -
For the sake of having it all in one thread - an FTP download example:
URL := 'ftp://remote_server/remote_folder/testfile.txt'; FTPRequest := WebRequest.Create(URL); Credentials := Credentials.NetworkCredential('some_login', 'some_password'); FTPRequest.Credentials := Credentials; FTPRequest.KeepAlive := FALSE; FTPRequest.UseBinary := TRUE; FTPRequest.Method := 'RETR'; FTPRequest.UsePassive := TRUE; FTPResponse := FTPRequest.GetResponse(); ResponseStream := FTPResponse.GetResponseStream(); FileStream := FileA.Create('c:\testfile.txt'); COPYSTREAM(FileStream, ResponseStream); FileStream.Close; --- WebRequest DotNet System.Net.WebRequest.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' FTPRequest DotNet System.Net.FtpWebRequest.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' Credentials DotNet System.Net.NetworkCredential.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' FTPResponse DotNet System.Net.FtpWebResponse.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' ResponseStream InStream FileStream DotNet System.IO.FileStream.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' FileA DotNet System.IO.File.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
Enjoy.1 -
I'm trying to use this for upload, but receive the following error - any ideas?
Best Regards
Mads Morre
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