FTP Upload error (WININET.DLL)

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi,


I am programming using VB.NET 2003.

Using 'wininet.dll', I have made a FTP upload() fuction which performs
two actions: 1)creates a new directory on FTP server and then 2)
transferes a file into the directory. If the program calls the
function once, it works fine. But if the function is called twice or
more in a program running, it fails to transfer the file to the FTP
server.

When it was called for the first time, it creates a directory, called
'NEW', under FTP server's root working directory and transfers a file,
'1st.txt', into the cerated directory.

On the second time when it's called, it seems that it tries to create
the directory, 'NEW', again, but the directory already exists.
Therefore, the attempt to create a new directory fails(ie.,
'FtpCreateDirectory' returns 'False').

After the attempt to create 'NEW' directory fails, it tries to
transfer a file, 2nd.txt', into 'NEW' directory. But this attempt also
fails (ie., 'FtpPutFile' returns 'False').

I have two questions about this behavior:
1) Before trying to create a directory on FTP server, is it possible
to check if the directory already exists and, if it does, do nothing?
I mean, can I make the program such that it just skips the attempt to
create the directory if the directory it's trying to create already
exists?

2) I think, when it's called for the second time, even if the attempt
to create the folder failed, the attempt to transfer the file should
succeed becuase the folder already exists and there should be nothing
wrong with the FtpPutFile method. But this attempt also fails (ie.,
'FtpPutFile' returns 'False') Why?


Below is the Upload() function I have. I have checked the variables
used in the function contain correct values in runtime.

Please have a look and let me know what is wrong.
Thank you very much in advance for your help.



Sub Upload(ByVal NewFileName As String, ByVal srcFilePath As
String, _
ByVal destFTPAddr As String, ByVal ID As String, ByVal PASS As
String)
Dim INet, INetConn As Integer
Dim RC, CD As Boolean
Dim RemoteNewdirectory As String

RemoteNewdirectory = "./NEW" + "/"
destPath = RemoteNewdirectory + NewFileName

INet = InternetOpen("FTP Connection",
INTERNET_OPEN_TYPE_PRECONFIG, vbNullString,_
vbNullString, 0)
INetConn = InternetConnect(INet, destFTPAddr, 21, ID, PASS,
INTERNET_SERVICE_FTP,_
INTERNET_FLAG_PASSIVE, 0)
CD = FtpCreateDirectory(INetConn, RemoteNewdirectory)
RC = FtpPutFile(INetConn, srcFilePath, destPath,
FTP_TRANSFER_TYPE_BINARY, 0)

'If RC Then MsgBox("File uploaded!")
If Not RC Then
err =
System.Runtime.InteropServices.Marshal.GetLastWin32Error()
MsgBox("Error occured")
InternetCloseHandle(INetConn)
End If
InternetCloseHandle(INet)
End Sub
.



Relevant Pages

  • FTP Upload Question (using wininet.dll)
    ... I have made a FTP upload() fuction which ... 1)creates a new directory on FTP server and then 2) ... it fails to transfer the file to the FTP ... Sub Upload(ByVal NewFileName As String, ...
    (microsoft.public.dotnet.languages.vb)
  • Re: FTP Upload error (WININET.DLL)
    ... In version 2005 and latter there is support for FTP in Net. ... it fails to transfer the file to the FTP ... Sub Upload(ByVal NewFileName As String, ... Dim RemoteNewdirectory As String ...
    (microsoft.public.dotnet.languages.vb)
  • FTP allows 47 files transfer but after that fails completely
    ... I've an FTP client developed in .NET 2.0 C# app. ... fails and that's it. ... The range of ports ... I found that I can login at the FTP server and issue ...
    (microsoft.public.pocketpc.developer)
  • RE: FTP Upload Question (using wininet.dll)
    ... 1)creates a new directory on FTP server and then 2) ... it fails to transfer the file to the FTP ... Before trying to create a directory on FTP server, ... Sub Upload(ByVal NewFileName As String, ...
    (microsoft.public.dotnet.languages.vb)
  • Re: upload excel and pdf file using Commons FileUpload package
    ... create a Web Based ftp to upload the file to the ftp server. ... String ftpUserId = userDetails.getName; ...
    (comp.lang.java.programmer)