FTP Upload error (WININET.DLL)

T

thomasc

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
 
C

Cor Ligthert[MVP]

Thomasc,

In version 2005 and latter there is support for FTP in Net.
This means that your problem is less actual for most people visiting this
newsgroup.

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top