Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

URGENT: FTP CONNECTION PROBLEM !!!

Posted on 2006-05-18
6
Medium Priority
?
490 Views
Last Modified: 2009-07-29
I have a windows service wich transfers files from local network FTP Site, through Local network FilesServer, to a Remote FTP Site (Outside Organisation Network)
I am using an .NET library  with namespace  "EnterpriseDT.Net.Ftp".
I tested service within our organisation network and it works fine, but when I'm trying to upload files remotly (outside our network) it failes.
I Should allso mention that I am able to log in and upload files to remote FTP Site using 3-rd Application Tools and also Command Prompt Window.

This is the code:
After I made a connection and authentication I am using these method to upload files to remote FTp site:


            If ftp Is Nothing Then
                ftp = New FTPClient
            End If
            'If Not ftp.IsConnected Then
            ftp.Timeout = 480 * 1000  ' 480 seconds, LeechFTP default connection timeout
            ftp.StrictReturnCodes = False
            'TODO: Set FTP IP Address
            Dim url As New System.Uri("ftp://111..11.11.11/")  'IP Address
            ftp.RemoteHost = url.Host()
            ftp.Connect()

            'TODO: Set User and Password for FTP Site
            ftp.Login("UserName", "Password")

         
            ftp.Put("C:\FOLDER_NAME\" & FileName, filename)  '****** This is main method for uploading the files********

 This is the exception text:

Task with ID Ftp failed on 5/18/2006 11:41:20 AM with message: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. Stack trace:
   at EnterpriseDT.Net.Ftp.FTPClient.PutASCII(Stream srcStream, String remoteFile, Boolean append)
   at EnterpriseDT.Net.Ftp.FTPClient.Put(String localPath, String remoteFile, Boolean append)
   at EnterpriseDT.Net.Ftp.FTPClient.Put(String localPath, String remoteFile)
   at Mediamaker.WebScheduler.FtpTask.upload() in C:\PROJEKTIFTP\FTP2\Mediamaker.WebScheduler\FtpTask.vb:line 331
   at Mediamaker.WebScheduler.FtpTask.ExecuteFtp(Uri url, String saveTo, Boolean disconnect, Boolean& failures) in C:\PROJEKTIFTP\FTP2\Mediamaker.WebScheduler\FtpTask.vb:line 162

Please if any one can provide me with any information !!??
0
Comment
Question by:TeKKeD
  • 3
  • 3
6 Comments
 
LVL 19

Expert Comment

by:Melih SARICA
ID: 16708378
Remote server timed out .. thats the problem
0
 

Author Comment

by:TeKKeD
ID: 16709040
In midtime I saw some articles on the WEB regarding Windows Errors and my err message :

Socket Error 10060 - Operation Timed Out


******
Error Number 10060:  A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.  
This error is quite self explanatory. It means that Windows reported that a connection attempt or idle connection timed out
If this error occurs during a connection attempt (eg in a VPOP3 - SMTP Client connection problem error message), then it means that Windows couldn't connect to the ISP mail server within a fixed time (the timeout limit is fixed within Windows itself). This problem can either mean that your ISP is having a problem, that you are connecting through a slow proxy (You can assign retry parameters on the Utilities -> Misc Settings -> Network Tweaks page), or that your Dial-up connection is faulty.

If this error occurs whilst a connection is in progress (eg in a VPOP3 - POP3 Client Problem error message), then it means that the connection was idle for a set time - this timeout time can be changed on the Utilities -> Misc Settings -> Network Tweaks page.

*******

I tried also to increase timeout, and tried with all other references, but it failed again... : (

0
 

Author Comment

by:TeKKeD
ID: 16715610
If there is a remote server timeout (and it is for sure), why it works with 3'rd tools and command prompt, what should I do within my app ??!!
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 19

Accepted Solution

by:
Melih SARICA earned 375 total points
ID: 16716368
it seems like ur Library cause this error ...
Here is the Microsoft SDK Sample for FTP Client

'---------------------------------------------------------------------
'  This file is part of the Microsoft .NET Framework SDK Code Samples.
'
'  Copyright (C) Microsoft Corporation.  All rights reserved.
'
'This source code is intended only as a supplement to Microsoft
'Development Tools and/or on-line documentation.  See these other
'materials for detailed information regarding Microsoft code samples.
'
'THIS CODE AND INFORMATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY
'KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
'IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
'PARTICULAR PURPOSE.
'---------------------------------------------------------------------

Imports System.Net
Imports System.IO

Module FtpSample

    Sub Main(ByVal args() As String)
        If args.Length = 0 OrElse args(0).Equals("/?") Then
            DisplayUsage()
        ElseIf args.Length = 1 Then
            Download(args(0))
        ElseIf args.Length = 2 Then
            If args(0).Equals("/list") Then
                List(args(1))
            Else
                Upload(args(0), args(1))
            End If
        Else
            Console.WriteLine("Unrecognized argument.")
        End If
    End Sub

    Private Sub DisplayUsage()
        Console.WriteLine("USAGE:")
        Console.WriteLine("    FtpSample [/? | <FTP download URL> | <local file>")
        Console.WriteLine("               <FTP upload URL> | /list <FTP list URL>]")
        Console.WriteLine()
        Console.WriteLine("where")
        Console.WriteLine("    FTP download URL   URL of a file to download from an FTP server.")
        Console.WriteLine("    FTP upload URL     Location on a FTP server to upload a file to.")
        Console.WriteLine("    FTP list URL       Location on a FTP server to list the contents of.")
        Console.WriteLine("    local file         A local file to upload to an FTP server.")
        Console.WriteLine()
        Console.WriteLine("    Options:")
        Console.WriteLine("        /?             Display this help message.")
        Console.WriteLine("        /list          Specifies the list command.")
        Console.WriteLine()
        Console.WriteLine("EXAMPLES:")
        Console.WriteLine("    Download a file    FtpSample ftp://myserver/download.txt")
        Console.WriteLine("    Upload a file      FtpSample upload.txt ftp://myserver/upload.txt")
    End Sub

    Private Sub Download(ByVal downloadUrl As String)
        Dim responseStream As Stream = Nothing
        Dim fileStream As FileStream = Nothing
        Dim reader As StreamReader = Nothing
        Try
            Dim downloadRequest As FtpWebRequest = _
                WebRequest.Create(downloadUrl)
            Dim downloadResponse As FtpWebResponse = _
                downloadRequest.GetResponse()
            responseStream = downloadResponse.GetResponseStream()

            Dim fileName As String = _
                Path.GetFileName(downloadRequest.RequestUri.AbsolutePath)

            If fileName.Length = 0 Then
                reader = New StreamReader(responseStream)
                Console.WriteLine(reader.ReadToEnd())
            Else
                fileStream = File.Create(fileName)
                Dim buffer(1024) As Byte
                Dim bytesRead As Integer
                While True
                    bytesRead = responseStream.Read(buffer, 0, buffer.Length)
                    If bytesRead = 0 Then
                        Exit While
                    End If
                    fileStream.Write(buffer, 0, bytesRead)
                End While
            End If
            Console.WriteLine("Download complete.")
        Catch ex As UriFormatException
            Console.WriteLine(ex.Message)
        Catch ex As WebException
            Console.WriteLine(ex.Message)
        Catch ex As IOException
            Console.WriteLine(ex.Message)
        Finally
            If reader IsNot Nothing Then
                reader.Close()
            ElseIf responseStream IsNot Nothing Then
                responseStream.Close()
            End If
            If fileStream IsNot Nothing Then
                fileStream.Close()
            End If
        End Try
    End Sub

    Private Sub Upload(ByVal fileName As String, ByVal uploadUrl As String)
        Dim requestStream As Stream = Nothing
        Dim fileStream As FileStream = Nothing
        Dim uploadResponse As FtpWebResponse = Nothing
        Try
            Dim uploadRequest As FtpWebRequest = WebRequest.Create(uploadUrl)
            uploadRequest.Method = WebRequestMethods.Ftp.UploadFile

            ' UploadFile is not supported through an Http proxy
            ' so we disable the proxy for this request.
            uploadRequest.Proxy = Nothing

            requestStream = uploadRequest.GetRequestStream()
            fileStream = File.Open(fileName, FileMode.Open)

            Dim buffer(1024) As Byte
            Dim bytesRead As Integer
            While True
                bytesRead = fileStream.Read(buffer, 0, buffer.Length)
                If bytesRead = 0 Then
                    Exit While
                End If
                requestStream.Write(buffer, 0, bytesRead)
            End While

            ' The request stream must be closed before getting the response.
            requestStream.Close()

            uploadResponse = uploadRequest.GetResponse()
            Console.WriteLine("Upload complete.")
        Catch ex As UriFormatException
            Console.WriteLine(ex.Message)
        Catch ex As IOException
            Console.WriteLine(ex.Message)
        Catch ex As WebException
            Console.WriteLine(ex.Message)
        Finally
            If uploadResponse IsNot Nothing Then
                uploadResponse.Close()
            End If
            If fileStream IsNot Nothing Then
                fileStream.Close()
            End If
            If requestStream IsNot Nothing Then
                requestStream.Close()
            End If
        End Try
    End Sub

    Private Sub List(ByVal listUrl As String)
        Dim reader As StreamReader = Nothing
        Try
            Dim listRequest As FtpWebRequest = WebRequest.Create(listUrl)
            listRequest.Method = WebRequestMethods.Ftp.ListDirectoryDetails
            Dim listResponse As FtpWebResponse = listRequest.GetResponse()
            reader = New StreamReader(listResponse.GetResponseStream())
            Console.WriteLine(reader.ReadToEnd())
            Console.WriteLine("List complete.")
        Catch ex As UriFormatException
            Console.WriteLine(ex.Message)
        Catch ex As WebException
            Console.WriteLine(ex.Message)
        Finally
            If reader IsNot Nothing Then
                reader.Close()
            End If
        End Try
    End Sub

End Module
0
 

Author Comment

by:TeKKeD
ID: 16716400
I made batch file for FTP Upload wich is called from service and so far it works fine
Thank you non zero
0
 
LVL 19

Expert Comment

by:Melih SARICA
ID: 16716418
Hold on .. What runs ur code is an Service ?
Somtimes Servcie Applications crash for Service Startup Account.
if ur application  is a Service, and if ur trying to access some local resources( files ) , Servcie Account must ave access to this job, And also.. If application is running under XP SP 2 and Firewall is active u must add ur application to the alowed application list with specified port

Melih SARICA
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question