FTP

Last post 11-10-2008 7:04 by pfrelek. 55 replies.
Page 2 of 4 (56 items) < Previous 1 2 3 4 Next >
Sort Posts: Previous Next
  • 05-25-2005 5:36 In reply to

    Re: FTP

    Thank you ctacke, I finally found the FTP sample in the Vault you mentioned. That was a great help...Once again, you guys do an awesome job.
  • 05-25-2005 9:05 In reply to

    Re: FTP

    By the way, if anyone is interested, I was able to convert the FTP Sample application from C# to VB.Net. The sample was great for my understanding of how to use the FTP classes.
  • 05-25-2005 11:06 In reply to

    Re: FTP

    ctacke, can you tell me where or how the GetFile was re-factored? This is the last hurdle I need to overcome in my application, to download a file from my FTP server and save it locally to my device.
  • 05-26-2005 8:28 In reply to

    Re: FTP

    Still working with the FTP classes in SDF v1.3 library. I have been able to figure out that the FTP sample as provided will accept a file download. However, the initial FTP connection made using Request/Repsponse classes handle the interaction with the server. To handle the actual transfer of a File from the FTP server, I need to specify a DataConnection to receive the file on. I found this out by inspecting the response ContentType. That method returns the following ApplicationException to me:

    Couldn't open passive data connection, no DataConnection IP was given

    So, my question is does anybody know how to specify the passive DataConnection?
  • 06-06-2005 2:21 In reply to

    Re: FTP

    Send the 'PASV' command or set the WebRequest object to Passive (it is a public bool property). Although it normally is set to passive in the constructor anyway.

    I am using 1.3 after Chris Tacke changed a lot of the code, so maybe you just need to upgrade because I don't even have a FTP.CS file my machine.

    Justin Heasman
    Office Mobile Solutions
    Software Development Manager
  • 06-06-2005 9:31 In reply to

    Re: FTP

    Hi,
    I am finding that the FTPSample runs but does not connect to
    my FTP server, failing to get a response. I can't find any reaspn for this. I am using the downloaded SDF binaries and compiling the FTPSample from the source obtained with the Vault client. If I try use the SDF from
    source, the sample exits abruptly.

    Any ideas?

    Thanks
  • 07-09-2005 3:58 In reply to

    Re: FTP

    I have problem using the FTP class from from OpenNETCT.NET.ftp to upload file. I can connect successfully to the ftp and able to upload file to the server. However the file upload has zero bytes. No data was send.
    Any ideas? I used the sample from the vault (FTPFile)

    Hi illancolombick,
    Are you using local address for your FTP server and connect through activesync using cradle? The FTP class use Dns to resolve the hostname, so you might get socket exception or Host unavailable error.
    I spent hours on this and only realize the cause.

  • 08-31-2005 5:06 In reply to

    Re: FTP

    Hi frends,
    i tried to use FTp classes and the sample provided in the Vault. I have created the FTP server in my machine. What Format of the path should be given to connect the FTPServer in the Device

    I have tried ftp://Mysys:Mysys@198.168.0.104 it works in the InternetExplorer of the Device But it Throws error as "Not Supported Exception". when i use it in the Code

    For e.g Mysys is FTP username
    and Mysys is the FTP Pwd and the machine Ip is 198.168.0.104


    The code to connect is as follows

    private void ConnectButton_Click_1(object sender, System.EventArgs e)
    {
    // When we connect, we create a control stream for the
    // indicated server.
    if ( !connected )
    {
    // Attempt to connect, using the URL entered by the
    // user as the server.
    try
    {
    // Create WebRequest.
    Uri ftpuri;
    if ( FTPServerText.Text.StartsWith( "ftp://" ) )
    {
    ftpuri = new Uri( FTPServerText.Text );
    }
    else
    {
    ftpuri = new Uri( "ftp://" + FTPServerText.Text );
    }
    ftpWebRequest = (FtpWebRequest)WebRequest.Create(ftpuri);

    // Getting the Request stream
    ftpRequestStream = ftpWebRequest.GetRequestStream();

    StreamReader reader = new StreamReader( ftpRequestStream );

    // Just ignore the result, but read it.
    String s = reader.ReadToEnd();

    // Relabel button.
    ConnectButton.Text = "Dis&connect";
    connected = true;
    }
    catch( Exception ex )
    {
    MessageBox.Show(ex.Message);
    // Mainly, don't change the button name
    // or the 'connected' flag.
    }
    }
    else
    {
    // OK, so we're already connected. Disconnect.
    if( ftpRequestStream != null )
    {
    StreamWriter writer = new StreamWriter( ftpRequestStream );
    writer.WriteLine("QUIT");
    writer.Flush();
    ftpRequestStream.Close();
    ftpRequestStream = null;
    }
    ftpWebRequest = null;

    // Relabel button.
    ConnectButton.Text = "&Connect";
    connected = false;
    }
    }

    Advance Thanks for Your Help


    sundar
  • 08-31-2005 13:50 In reply to

    Re: FTP

    Sundar, you need to pass username and password through a NetworkCredential object

    so your connection code should be something like;


    // Building our URI object
    Uri ftpuri;
    if( txtServer.Text.IndexOf( "ftp:" ) != 0 )
    ftpuri = new Uri( "ftp://"+txtServer.Text );
    else
    ftpuri = new Uri( txtServer.Text );

    // Creating a new FtbRequest object
    request = (FtpWebRequest)WebRequest.Create( ftpuri );

    //replace username and password with correct values
    request.Credentials = new NetworkCredential( Username, Password );

    // Getting the Request stream
    ftpRequestStream = request.GetRequestStream();

    StreamReader reader = new StreamReader( ftpRequestStream );
    string s = reader.ReadToEnd();


    good luck
  • 08-31-2005 22:54 In reply to

    Re: FTP

    quote:
    Originally posted by PaulAustin

    Sundar, you need to pass username and password through a NetworkCredential object

    so your connection code should be something like;


    // Building our URI object
    Uri ftpuri;
    if( txtServer.Text.IndexOf( "ftp:" ) != 0 )
    ftpuri = new Uri( "ftp://"+txtServer.Text );
    else
    ftpuri = new Uri( txtServer.Text );

    // Creating a new FtbRequest object
    request = (FtpWebRequest)WebRequest.Create( ftpuri );

    //replace username and password with correct values
    request.Credentials = new NetworkCredential( Username, Password );

    // Getting the Request stream
    ftpRequestStream = request.GetRequestStream();

    StreamReader reader = new StreamReader( ftpRequestStream );
    string s = reader.ReadToEnd();


    good luck



    sundar
  • 08-31-2005 23:03 In reply to

    Re: FTP

    quote:
    Originally posted by PaulAustin

    Sundar, you need to pass username and password through a NetworkCredential object

    so your connection code should be something like;


    // Building our URI object
    Uri ftpuri;
    if( txtServer.Text.IndexOf( "ftp:" ) != 0 )
    ftpuri = new Uri( "ftp://"+txtServer.Text );
    else
    ftpuri = new Uri( txtServer.Text );

    // Creating a new FtbRequest object
    request = (FtpWebRequest)WebRequest.Create( ftpuri );

    //replace username and password with correct values
    request.Credentials = new NetworkCredential( Username, Password );

    // Getting the Request stream
    ftpRequestStream = request.GetRequestStream();

    StreamReader reader = new StreamReader( ftpRequestStream );
    string s = reader.ReadToEnd();


    good luck



    sundar
  • 08-31-2005 23:23 In reply to

    Re: FTP

    Dear Paul,

    I tried to use u'r code but even though it is throwing "Not supported exception" .

    This time I have tried the Different code in the vault it is successfull upto Connection but for uploading a file from the Device to pocket Pc it is Throwing Exception.

    Particularly during the Binary Writer...in uploading


    The Code IS as follows.

    private void Connect()
    {
    FtpRequestCreator creator = new FtpRequestCreator();
    WebRequest.RegisterPrefix( "ftp:", creator );

    // Building our URI object
    Uri testUri;
    if( txtServer.Text.IndexOf( "ftp:" ) != 0 )
    testUri = new Uri( "ftp://"+txtServer.Text );
    else
    testUri = new Uri( txtServer.Text );

    // Creating a new FtbRequest object
    request = (FtpWebRequest)WebRequest.Create( testUri );
    request.Credentials = new NetworkCredential( txtUsername.Text, txtPassword.Text );

    // Getting the Request stream
    ftpRequestStream = request.GetRequestStream();

    StreamReader reader = new StreamReader( ftpRequestStream );
    txtServerCtrlResp.Text = reader.ReadToEnd();
    }


    private void btnConnect_Click(object sender, System.EventArgs e)
    {

    txtServerCtrlResp.Text = "";
    txtServerDataResp.Text = "";
    inputPanel1.Enabled = false;
    Cursor.Current = Cursors.WaitCursor;
    try
    {
    if( ftpRequestStream == null )
    {
    Connect();
    btnConnect.Text = "Disconnect";
    txtServer.Enabled = false;
    txtUsername.Enabled = false;
    txtPassword.Enabled = false;
    btnSendCommand.Enabled = true;
    txtCommand.Enabled = true;

    // Setting default command to retrieval of remote files...
    txtCommand.Text = "LIST";
    }
    else
    {
    CloseConnection();
    btnConnect.Text = "Connect";
    txtServer.Enabled = true;
    txtUsername.Enabled = true;
    txtPassword.Enabled = true;
    btnSendCommand.Enabled = false;
    txtCommand.Enabled = false;
    }
    }
    catch( Exception err )
    {
    MessageBox.Show( err.Message );
    }
    finally
    {
    Cursor.Current = Cursors.Default;
    }


    }


    private void BrowseButton_Click(object sender, System.EventArgs e)
    {
    // User wants to browse for the local file name. Let him, then
    // enter the result into the LocalFilePathText.
    // saveFileDialog1.Filter = "All files (*.*)|*.*";
    // saveFileDialog1.FilterIndex = 1;


    //if ( saveFileDialog1.ShowDialog() == DialogResult.OK )
    if ( openFileDialog1.ShowDialog() == DialogResult.OK )
    {
    // Get the full file name and put it in the right field.
    // LocalFilePathText.Text = saveFileDialog1.FileName;
    LocalFilePathText.Text = openFileDialog1.FileName;
    }
    }

    private void UploadButton_Click(object sender, System.EventArgs e)
    {
    // Upload the local file to the specified remote file.

    try
    {
    StreamReader reader;
    String commandReply;


    // Open the input file. If the file does not exist, it's an
    // error.
    FileStream fs = new FileStream( LocalFilePathText.Text, FileMode.Open );

    // Create the reader for the local file data.
    BinaryReader r = new BinaryReader( fs );

    // Opening the data connection, this must be done before
    // we issue the command.
    Stream ftpResponseStream = request.GetResponse().GetResponseStream();
    BinaryWriter response = new BinaryWriter( ftpResponseStream );

    // Prepare to send commands to the server.
    StreamWriter writer = new StreamWriter( ftpRequestStream );

    // Set transfer type to IMAGE (binary).
    writer.Write( "TYPE I\r\n" );
    writer.Flush();

    // Reading the request output
    reader = new StreamReader( ftpRequestStream );
    commandReply = reader.ReadToEnd();

    // Write the command to the request stream.
    String cmd = "stor " + RemoteFilePathText.Text + "\r\n";
    writer.Write( cmd );
    writer.Flush(); // We MUST flush before we start reading from
    // both response and request

    // Reading the request output
    commandReply = reader.ReadToEnd();

    // Allocate buffer for the data, which will be written in blocks.
    int bufsize = 1024;
    byte[] buf = new byte[ bufsize ];
    int xcount;

    while ( ( xcount = r.Read( buf, 0, bufsize ) ) > 0 )
    {
    // Send next buffer over the data connection.
    response.Write( buf, 0, xcount );
    }

    r.Close();
    fs.Close();

    response.Close();

    reader.Close();
    }
    catch( Exception err )
    {
    MessageBox.Show( err.Message );
    }
    }

    private void DownloadButton_Click(object sender, System.EventArgs e)
    {
    // Download the remote file to the specified local file.

    try
    {
    StreamReader reader;
    String commandReply;

    // Create the output file. If the file already exists,
    // truncate it.
    FileStream fs = new FileStream( LocalFilePathText.Text, FileMode.Create );

    // Create the writer for data.
    BinaryWriter w = new BinaryWriter( fs );

    // Opening the data connection, this must be done before
    // we issue the command.
    Stream ftpResponseStream = request.GetResponse().GetResponseStream();
    BinaryReader response = new BinaryReader( ftpResponseStream );

    StreamWriter writer = new StreamWriter( ftpRequestStream );

    // Set transfer type to IMAGE (binary).
    writer.Write( "TYPE I\r\n" );
    writer.Flush();

    // Reading the request output
    reader = new StreamReader( ftpRequestStream );
    commandReply = reader.ReadToEnd();

    // Write the command to the request stream.
    String cmd = "retr " + RemoteFilePathText.Text + "\r\n";
    writer.Write( cmd );
    writer.Flush(); // We MUST flush before we start reading from
    // both response and request

    // Reading the request output
    commandReply = reader.ReadToEnd();

    // Allocate buffer for the data, which will be read in blocks.
    int bufsize = 1024;
    byte[] buf = new byte[ bufsize ];
    int xcount;

    while ( ( xcount = response.Read( buf, 0, bufsize ) ) > 0 )
    {
    // Write the next buffer to the file.
    w.Write( buf, 0, xcount );
    }

    w.Close();
    fs.Close();

    response.Close();

    reader.Close();
    }
    catch( Exception err )
    {
    MessageBox.Show( err.Message );
    }
    }


    Pls find how this can be sorted.....

    Thanks

    sundar
  • 09-01-2005 10:45 In reply to

    Re: FTP

    Trying to open a active connection to Windows XP IIS FTP.
    Everything works accept when I try to read from the ftpReponseStream. When I debug I find that the socket has no RemoteIPEndpoint defined. Looking at the FTPWebRequest, OpenActiveDataConnection()

    private void OpenActiveDataConnection()
    {
    Socket dataSocket = new Socket( AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp );
    IPHostEntry localhostEntry = Dns.GetHostByName( Dns.GetHostName() );
    IPEndPoint listener = new IPEndPoint( localhostEntry.AddressList[0], 0);
    dataSocket.Bind( listener );
    dataSocket.Listen( 5 );
    IPEndPoint localEP = (IPEndPoint)dataSocket.LocalEndPoint;
    UInt32 localEPAddress = (UInt32) localEP.Address.Address;
    string local = FormatAddress( localEPAddress, localEP.Port );
    CommandResponse response = SendCommand( "PORT", local );
    dataStream = new FtpDataStream( dataSocket );
    }

    The only question I have is should

    dataStream = new FtpDataStream( dataSocket );

    be

    dataStream = new FtpDataStream( dataSocket.Accept() );

    to accept the Remote IPEndpoint?
  • 09-02-2005 5:26 In reply to

    Re: FTP

    Hello to everyone,


    Does any body succeeded while Uploading the File from the Device to desktop.

    Iam Successful upto Connection/disconnect, Downloading the File From Desktop to the Device.

    I used the Code from the Vault and Found Exception in Uploading.
    The Code is As follows:

    private Stream ftpRequestStream;
    private FtpWebRequest request;


    private void UploadButton_Click(object sender, System.EventArgs e)
    {

    // Upload the local file to the specified remote file.

    try

    {
    StreamReader reader;
    String commandReply;

    // Open the input file. If the file does not exist, it's an
    // error.
    FileStream fs = new FileStream(LocalFilePathText.Text, FileMode.Open);

    // Create the reader for the local file data.
    BinaryReader r = new BinaryReader( fs );

    // Opening the data connection, this must be done before
    // we issue the command.
    System.IO.Stream ftpResponseStream = request.GetResponse().GetResponseStream();

    BinaryWriter response = new BinaryWriter(ftpResponseStream); // ***** Binary Writer is not properly working

    // Prepare to send commands to the server.
    StreamWriter writer = new StreamWriter( ftpRequestStream );

    // Set transfer type to IMAGE (binary).
    writer.Write( "TYPE I\r\n" );
    writer.Flush();

    // Reading the request output
    reader = new StreamReader( ftpRequestStream );
    commandReply = reader.ReadToEnd();

    // Write the command to the request stream.
    String cmd = "stor " + RemoteFilePathText.Text + "\r\n";
    writer.Write( cmd );
    writer.Flush(); // We MUST flush before we start reading from
    // both response and request

    // Reading the request output
    commandReply = reader.ReadToEnd();

    // Allocate buffer for the data, which will be written in blocks.
    int bufsize = 1024;
    byte[] buf = new byte[ bufsize ];
    int xcount;

    while ( ( xcount = r.Read( buf, 0, bufsize ) ) > 0 )
    {
    // Send next buffer over the data connection.
    response.Write( buf, 0, xcount );
    //w.Write( buf, 0, xcount );
    }

    r.Close();
    fs.Close();

    response.Close();

    reader.Close();
    }
    catch( Exception err )
    {
    MessageBox.Show( err.Message );
    }

    }


    In the above code the Marked line is throwing the Exception

    The Problem is that the ftpResponseStream is only -- Can Read

    So while Passing this the Arguement Exception is thrown by the Binary Writer Function.


    Does Any body have any solution for this.

    as Iam involved in it very much.

    Thanks


    sundar
  • 10-29-2005 2:24 In reply to

    Re: FTP

    Hi there~
    Is it via FTP sample, if I wanna download file from webservice?
    I mean...If I want to download a file, and the file is at http://......
    but it's not use for id/pw,right??
Page 2 of 4 (56 items) < Previous 1 2 3 4 Next >