Advertisement

05.11.2004 at 05:47AM PDT, ID: 20985216
[x]
Attachment Details

WININET.dll  FTP transfer not working correctly.

Asked by comt00006 in Programming for ASP.NET

Tags:

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.InteropServices

Public Class FTP

    <DllImport("WININET.DLL", _
     EntryPoint:="InternetCloseHandle")> _
     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:="InternetConnectA")> _
     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 = objFTP.Open("WebClientFtpTransfer", 0, Microsoft.VisualBasic.ControlChars.NullChar, Microsoft.VisualBasic.ControlChars.NullChar, 0)

            If (intInetSession = 0) Then
                Throw New System.Exception("Could not connect to the internet.")
            End If

            ' Connect to the FTP server
            intFTPSession = objFTP.Connect(intInetSession, "NCA6721068E", 21, "", "", 1, 0, 0)

            If (intFTPSession = 0) Then
                Throw New System.Exception("Could not connect to FTP client")
            End If

            blnSuccess = objFTP.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
[+][-]05.11.2004 at 07:56AM PDT, ID: 11041167

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.11.2004 at 08:01AM PDT, ID: 11041208

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.11.2004 at 08:06AM PDT, ID: 11041261

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.11.2004 at 08:18AM PDT, ID: 11041383

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.11.2004 at 08:22AM PDT, ID: 11041424

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Programming for ASP.NET
Tags: ftp
Sign Up Now!
Solution Provided By: dante469
Participating Experts: 1
Solution Grade: A
 
 
[+][-]05.11.2004 at 08:28AM PDT, ID: 11041492

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.11.2004 at 08:49AM PDT, ID: 11041746

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32