 |
|
 |
Unknown error code: 1008
hInternetConnection = FtpDll.InternetConnect(hInternetSession, strHostURL, FtpDll.DEFAULT_FTP_PORT, strUser, strPW, FtpDll.SERVICE_FTP, 0, 0);
if (funGetError())
throw new Exception("funIConnect failed, error value: " + intErrorValue + " - " + strErrorText);
|
|
|
|
 |
|
 |
Not sure if anyone else ran into this but I found this code throws exceptions if you try to open a connection twice in the same instance of a program.
Better put by an example:
FtpDll ftp = new FtpDll();
ftp.funIConnect(); ftp.funFTPChangeDir("/tffs0");
ftp.funFTPPutFile("codeldr", "codeldr");
ftp.funFTPDisconnect();
ftp.funIConnect(); ftp.funFTPChangeDir("/tffs0/scripts"); ftp.funFTPDisconnect();
If you wonder why I connect/disconnect twice, it's the same as if I clicked a button twice in my GUI. I traced the problem to the funIOpen() function, specifically the call to wininet.dll's InternetOpen() function.
public void funIOpen()
{
string strProxy = "";
string strProxyBypass = "";
try
{
funClearError(); hInternetSession = FtpDll.InternetOpen("FTPTest", FtpDll.OPEN_TYPE_DIRECT, strProxy, strProxyBypass, 0);
if (funGetError())
I looked up the definition of InternetOpen on MSDN(see http://msdn.microsoft.com/en-us/library/aa385096%28VS.85%29.aspx[^])
Basically it states that for the proxy and proxybypass "Do not use an empty string, because InternetOpen will use it as the proxy name." HMMMM. Big red light should go off here.
Changing these two lines clears the problem right up. The MSDN states "If dwAccessType is not set to INTERNET_OPEN_TYPE_PROXY, this parameter is ignored and should be NULL." For once microsoft did help.
string strProxy = null;
string strProxyBypass = null;
Hopefully this helps anyone still stumbling onto this via Google, much as I did.
|
|
|
|
 |
|
 |
There is absolutely no discussion of the code in your article.
|
|
|
|
 |
|
 |
"Discussion" ??
Do you want to say "Comment" ?
|
|
|
|
 |
|
 |
Hello
If you search a comfortable and reusable FTP client,
-- which is running on .NET Framework 1.1 or higher,
-- which can automatically put together splitted files on the server,
-- which allows to download only a part of a file on the server,
-- which allows to resume any broken download,
-- which automatically starts a separate thread,
-- which can be aborted any time from your main thread,
-- which supports UTF8 encoded filenames,
-- which has a built-in download scheduler,
-- which has a built-in bandwidth control,
-- which has a built-in preview function for the download of movies,
-- which automatically reconnects the server after an error has occurred,
-- which displays download progress in percent and in bytes and the remaining time,
-- which writes a detailed logging for all operations it does,
-- which is based on Wininet.dll and has one workaround for each of the 4 known Wininet.dll bugs,
-- which is very well tested and bug-free,
-- which is written by a very experienced programmer and has a very clean and well documented sourcecode,
then have a look at this project:
ElmueSoft Partial FTP Downloader[^]
Elmü
|
|
|
|
 |
|
 |
Advertising your own code in someone else's article (without being asked) is not cool, even if it *is* at CodeProject.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
 |
|
 |
Hello
This is not an advertise!
Do you think I earn one penny with offering my code on Codeproject ???
Its the opposite: I inversted many days of hard work writing it and offer it for FREE !!
What has this to do with advertising ???
Definitely NOTHING!
An advertise is something which you put to earn more money!
It doesnt interest me how many people download my code.
I dont profit from that!
I dont even know how many people read this!
The people come here from Googe and find a code which will not help them much.
The code you can download in this article is very basic.
It does not have none of the 4 important workarounds for WinInet bugs which you find in my code.
Additionally my code offers much much more functionality than this one here.
So the ones who need a comfortable library for FTP will not be very happy with what they found here.
My posting informs them that there is a more elaborate code and they can find it without further Googleing.
I do not profit from that!
Elmü
|
|
|
|
 |
|
 |
Hello,
I'm searching an FTP library, in .NET, which allows sending such a command as of Subject.
Yours, can?
|
|
|
|
 |
|
 |
funFTPFirstFile() works quit well, but does anybody has an idea how to get every file of a directory and not only the first one?
|
|
|
|
 |
|
 |
//use InternetFindNextFile
[DllImport("wininet.dll", CharSet = CharSet.Auto)]
public static extern bool InternetFindNextFile(IntPtr hFind,[In,Out] FileData dirData);
|
|
|
|
 |
|
 |
should be something like:
[DllImport("wininet.dll", CharSet = CharSet.Auto)]
public static extern bool InternetFindNextFile(IntPtr ulFindFirst, [In, Out] FileData dirData);
...
IntPtr hFind = new IntPtr(0);
...
public Hashtable funGetFilesInDir(string strPath)
{
string strFileName = "";
Hashtable fileList = new Hashtable();
try
{
strFileName = funFTPFirstFile(strPath);
if (strFileName.Equals(""))
{
fileList = null;
}
else
{
do
{
Console.WriteLine(myFileData.fileName);
fileList.Add(myFileData.fileName, myFileData.fileAttributes);
} while (InternetFindNextFile(hFind, myFileData));
}
return fileList;
}
catch (Exception e)
{
fileList = null;
if (bolDebug) Console.WriteLine(e.Message);
throw e; }
}
|
|
|
|
 |
|
 |
Anyone interested to use this code in a .Net 2 environment should replace "ulong" with "uint" because the .Net CLR detects incorrect function mappings and throws PInvokeStackImbalance exceptions. in my experience none of the FTP functions will work without this change.
hope this helps anybody else out there who encounteres the same problem.
tim.
|
|
|
|
 |
|
|
 |
|
 |
Thank you very much for this comment. I appreciate the code but it just doesn't work and doesn't give a decent error code to understand. After changing ulong to uint, everything works perfect. Thank you very much.
|
|
|
|
 |
|
 |
thanks...
(wished I read this before a lot of searching and trying and so on)
but thanks; now it works
|
|
|
|
 |
|
 |
many many thank you,buddy!
|
|
|
|
 |
|
 |
In
public bool funGetError()
case 12003: //ERROR_INTERNET_EXTENDED_ERROR
call to InternetGetLastResponseInfo _OVERWRITES_ (zeroes)
the value of intErrorValue. There are 2 such calls. That's why in such cases funGetError() returnes FALSE.
I do not think this is by design. To fix, just add
uint intErrorValue = 0; as a first line in the try block.
Otherwise it as workable solution. At least can be used as starting point for ftp file manipulation from .net.
BTW, NET 2.0 introduces ftp client functionality, but some pieces are still missing. So I concider Wininet a better solution.
Lev Elbert
|
|
|
|
 |
|
 |
Here is the flag you need to add to put WinInet in passive mode
uint flags = 0x08000000; //INTERNET_FLAG_PASSIVE;
hInternetConnection = FtpDll.InternetConnect(hInternetSession, strHostURL, FtpDll.DEFAULT_FTP_PORT, strUser, strPW, FtpDll.SERVICE_FTP, flags, 0);
http://www.adamloving.com
|
|
|
|
 |
|
 |
Hi! The client worked perfectly for mi when I tryed it in a lan without a proxy that shares the connection.
Now, in the other scenario (with the proxy between my Lan and Internet) I got the "funIConnect failed, error value: 3" when funIConnect method executes.
So, It worked in a machine connected directly to internet, but did not work in other in a LAN with an internet proxy. I have to set the gateway or something like that ?
Thanks in advance.
alvaro
|
|
|
|
 |
|
 |
According to the Win32 SDK, 3 has to do with "Path not found" ... I changed the hostname (in my case "localhost" was not quite working out for me!) to an IP address (127.0.0.1) and it worked just fine ... stupid problem, stupid solution ... but hey, I'm just happy that it works ... try something that would resolve properly ... as a last ditch effort, try the IP address.
|
|
|
|
 |
|
 |
using IP does NOT work either. any permanent solution to this?
|
|
|
|
 |
|
 |
see Important Note above to fix, replace ulong w/ uint
|
|
|
|
 |
|
 |
Can anybody suugest how can we implement the connection timeout while it try to connect with ftp server. As we know there is property exposed by winInet API to set the connection timeout.
|
|
|
|
 |
|
 |
Hello. I am trying to use the wininet.dll to automate transfer of schedule files to a machine that performs operations based on those schedule files. The box seems to lock the files after it loads them. When I try to FTP the new schedule with the same name as the old, it will fail due to the file being locked. (Note that the wininet error handling does not generate an error, but I have an error logging program running on my FTP server that tells me this is why the operation failed). If I reboot my ftp server, I can then ftp the new file. Does the wininet.dll have any convention for overwriting a file that is locked on an ftp server? I haven't seen anything in the Microsoft documentation.
Thanks,
Kevin
|
|
|
|
 |
|
|
 |