Hi there.
I have a little app that runs using ASP.NET. I would like to transfer files using FTP over an intranet. I am using the windows object "WININET.dll " as follows:
Imports System.Runtime.InteropServ
ices
Public Class FTP
<DllImport("WININET.DLL", _
EntryPoint:="InternetClose
Handle")> _
Public Shared Function CloseConnection(ByVal _
HINet As Integer) As Integer
End Function
<DllImport("WININET.DLL", _
EntryPoint:="InternetOpenA
")> _
Public Shared Function Open(ByVal _
sAgent As String, ByVal lAccessType _
As Integer, ByVal sProxyName As String, _
ByVal sProxyBypass As String, _
ByVal lFlags As Integer) As Integer
End Function
<DllImport("WININET.DLL", _
EntryPoint:="InternetConne
ctA")> _
Public Shared Function Connect( _
ByVal hInternetSession As Integer, _
ByVal sServerName As String, _
ByVal nServerPort As Integer, _
ByVal sUsername As String, _
ByVal sPassword As String, _
ByVal lService As Integer, _
ByVal lFlags As Integer, _
ByVal lContext As Integer) As Integer
End Function
<DllImport("WININET.DLL", _
EntryPoint:="FtpPutFileA")
> _
Public Shared Function PutFile( _
ByVal hFtpSession As Integer, _
ByVal lpszLocalFile As String, _
ByVal lpszRemoteFile As String, _
ByVal dwFlags As Integer, _
ByVal dwContext As Integer) As Boolean
End Function
<DllImport("WININET.DLL", _
EntryPoint:="FtpGetFileA")
> _
Public Shared Function GetFile( _
ByVal hFtpSession As Integer, _
ByVal lpszRemoteFile As String, _
ByVal lpszNewFile As String, _
ByVal fFailIfExists As Boolean, _
ByVal dwFlagsAndAttributes As Integer, _
ByVal dwFlags As Integer, _
ByVal dwContext As Integer) As Boolean
End Function
End Class
The problem that I am having is that every file that I PUT on the server is taken from the server. The Function "PutFile()" has parameters wich 2 of them are "Local File" and "Remote File". I can assume that the local file is the file you want to put on the server from your local PC and the remote file is the one you want to name on the server. My problem is that this function takes the file from the server and puts it back on the server. I want the file to be taken from the client and put to the server. Here is my code which calls my "FTP" class.
Code Starts
--------------------------
----------
----------
----------
----------
----
objFTP = New FTP
' Connect to the internet
intInetSession = obj
FTP.Open("WebClientFtpT
ransfer", 0, Microsoft.VisualBasic.Cont
rolChars.N
ullChar, Microsoft.VisualBasic.Cont
rolChars.N
ullChar, 0)
If (intInetSession = 0) Then
Throw New System.Exception("Could not connect to the internet.")
End If
' Connect to the FTP server
intFTPSession = obj
FTP.Connect(intInetSession, "NCA6721068E", 21, "", "", 1, 0, 0)
If (intFTPSession = 0) Then
Throw New System.Exception("Could not connect to FTP client")
End If
blnSuccess = obj
FTP.PutFile(intFTPSession, "C:\mine.txt", "mine.txt", 0, 0)
If (Not (blnSuccess)) Then
Throw New System.Exception("File transfer did not succeed")
End If
--------------------------
----------
----------
----------
---
End code
Everything works fine but like I said the file "C:\mine.txt" is take from the server and put back on the server in the FTP root directory. How do I get this to work for the client file "C:\mine.txt"?
Thanks in advance.
Start Free Trial