FTP Upload Question (using wininet.dll)
- From: thomasc <thomasc1020@xxxxxxxxx>
- Date: Wed, 18 Feb 2009 15:44:07 -0800 (PST)
Hi,
I am programming using VB.NET 2003 and
cannot use other versions such as VB 2005.
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.
I am using VB.NET 2003 and cannot use other versions such as VB 2005.
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
.
- Follow-Ups:
- RE: FTP Upload Question (using wininet.dll)
- From: Family Tree Mike
- RE: FTP Upload Question (using wininet.dll)
- Prev by Date: Re: bug: active MDI child window does not show the menu
- Next by Date: Re: Upgrading to VB.Net
- Previous by thread: Sample VB.NET code to add items to Sharepoint Document Library
- Next by thread: RE: FTP Upload Question (using wininet.dll)
- Index(es):
Relevant Pages
|