FTP Transfer with Dotnet

asmilie2b
Member Posts: 122
THis may be more of a webservice related issue than NAV, but if anyone had any ideas I would love to hear them. I am using the method explained here to upload a file by FTP:
viewtopic.php?f=32&t=51988
It gives the below error:
This message is for C/AL programmers: A call to System.Net.FtpWebRequest.GetRequestStream failed with this message: The requested FTP command is not supported when using HTTP proxy.
I have tried what other forums recommend which is using one of either of the below two commands, but these don't seem to be supported params (none / nothing)
request.Proxy := None;
request.Proxy := Nothing;
viewtopic.php?f=32&t=51988
It gives the below error:
This message is for C/AL programmers: A call to System.Net.FtpWebRequest.GetRequestStream failed with this message: The requested FTP command is not supported when using HTTP proxy.
I have tried what other forums recommend which is using one of either of the below two commands, but these don't seem to be supported params (none / nothing)
request.Proxy := None;
request.Proxy := Nothing;
Bruce Anderson
0
Comments
-
I have taken a different approach with this. I have used the tool "WebDrive" which maps an ftp location as a shared drive. So then all I need to do is save the file from NAV and Windows takes care of the file transfers. Actually working so well I might just stick with it, but I would like to resolve the FTP in dotnet sometime.
Bruce Anderson0 -
Hi!
here is some more in depth insight on the Proxy attribute: http://msdn.microsoft.com/en-us/library ... xy(v=vs.90).aspx
apparently your system has a proxy preset. If you want to ignore those settings you need to define a new variable to call GloblaProxySelection:defaultProxy DotNet 'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Net.GlobalProxySelection
which has a method called "GetEmptyWebProxy".
This hopefully does the trick. I haven't tested it on my system.0 -
Hello StLi,
Many thanks for the info! I wil give that a try.
Bruce Anderson0 -
Hello StLi,
I was taking a look into this. Unfortunately your link seems broken?
If I add the dotnet, I can call:
DefaultProxy.GetEmptyWebProxy,
but I am not sure what to do with it.
I tried adding this:
FTPRequest.Proxy := DefaultProxy.GetEmptyWebProxy;
Then I get this:
This message is for C/AL programmers: A DotNet variable has not been instantiated. Attempting to call System.Net.FtpWebRequest.Proxy in CodeUnit FTP Transfer: Testdotnetftp
I didn't know we had to instantiate a dotnet variable.. (new to dotnet in NAV suffice it to say). I tried CREATE(DefaultProxy), but that gives an error that dotnet variables cannot be used with create. ](*,)
Bruce Anderson0 -
.Net Variables need to be instantiated like you do in normal .net code, you need to call their constructor (of course this only applies to non static types).
You do this like this:
<VariableName> := <VariableName>.<ClassName>(<parameter1>,<parameter2>);
If you hit F5 you will get a list of constructors in the Symbol Menu. You will find in this exmaple that only the default constructor with empty parameters is available.
The call would look like this:DefaultProxy := DefaultProxy.GlobalProxySelection;
btw here is the correct link: http://msdn.microsoft.com/de-ch/library/system.net.globalproxyselection.aspx
But you can always type the class name in google and 99% of the times the msdn reference about it will come up as first result0 -
Thank you!!
With your info I was able to get it to work. Much appreciated.defaultProxy := DefaultProxy.GlobalProxySelection; URL := 'ftp://myserver.com/test/testfile.txt'; FTPRequest := WebRequest.Create(URL); Credentials := Credentials.NetworkCredential('***', '***'); FTPRequest.Proxy := defaultProxy.GetEmptyWebProxy; 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);
Bruce Anderson0 -
Now the file upload is working, if someone would be that much of a saviour and give me a hint on how I can get the file download working it would be much appreciated.
After logging into the server with this:
defaultProxy := DefaultProxy.GlobalProxySelection;
URL := 'ftp://myserver.com/test/testfile.txt';
FTPRequest := WebRequest.Create(URL);
Credentials := Credentials.NetworkCredential('***', '***');
FTPRequest.Proxy := defaultProxy.GetEmptyWebProxy;
FTPRequest.Credentials := Credentials;
FTPRequest.KeepAlive := FALSE;
FTPRequest.UseBinary := TRUE;
FTPRequest.Method := 'STOR';
FTPRequest.UsePassive := TRUE;
FileStream := FileA.OpenRead('c:\testfile.txt');
I tried this then to retrieve from ftp (Changing FileA.OpenRead to FileA.OpenWrite - OK yes I am guessing here)
----
FileStream := FileA.OpenWrite('c:\testfile.txt');
FTPRequest.GetRequestStream.Write(FileA.ReadAllBytes('c:\testfile.txt'), 0, FileStream.Length);
----
But it seems to trip over itself with the error:
"A call to System.IO.File.ReadAllBytes failed with this message: The process cannot access the file 'c:\testfile.txt' because it is being used by another process."
Bruce Anderson0
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