Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 3.5 and Visual Studio. 2008 > Visual Studio 2008
|
Visual Studio 2008 For discussing Visual Studio 2008. Please post code questions about a specific language (C#, VB, ASP.NET, etc) in the correct language forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Studio 2008 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 8th, 2010, 06:49 PM
Registered User
 
Join Date: Apr 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default ftp to unix from windows service problem

So I have this app that I am converting to a windows service so it can run unattended. While I was building this as an app with a GUI this portion of the code works just fine. When I migrated the code over to a windows service, it looks as if it works, however the file does not get uploaded.

original code from here
FTP from inside VB.NET Program


Code:
    Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal HINet As Integer) As Integer
    Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Integer, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Integer) As Integer
    Private Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" (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
    Private Declare Function FtpGetFile Lib "wininet.dll" Alias "FtpGetFileA" (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
    Private Declare Function FtpPutFile Lib "wininet.dll" Alias "FtpPutFileA" (ByVal hFtpSession As Integer, ByVal lpszLocalFile As String, ByVal lpszRemoteFile As String, ByVal dwFlags As Integer, ByVal dwContext As Integer) As Boolean


    Public Sub test(ByVal sFileName As String, ByVal fiFullName As String, ByVal sOrgPath As String, ByVal sNewPath As String)

        Dim ServerName As String
        Dim sPort As Integer
        Dim FTPLogin As String
        Dim FTPPassword As String
        ' --------------------
        ' Transfer via standard FTP
        ServerName = ""
        sPort = 
        FTPLogin = ""
        FTPPassword = ""

        Try
            ' Instantiate a new FTP object
            Dim INet, INetConn As Integer
            Dim RC As Boolean
            ' FTP_TRANSFER_TYPE_ASCII
            ' FTP_TRANSFER_TYPE_BINARY
            INet = InternetOpen("DMGImport_FTP", 1, vbNullString, vbNullString, 0)
            INetConn = InternetConnect(INet, ServerName, sPort, FTPLogin, FTPPassword, 1, 0, 0)
            RC = FtpPutFile(INetConn, fiFullName, sNewPath & sFileName, 0, 0)

            If RC Then
                'MsgBox("Transfer succesfull!")
            End If
            InternetCloseHandle(INetConn)
            InternetCloseHandle(INet)
        Catch ex As Exception

        End Try
    End Sub
so to recap,
When used as an application that I have to interact with the file is uploaded

When I change this to a service, and set the service to run with my credentials, the file is not uploaded nor is there an error.

What could cause this? When I run the code in debug, everything looks good. The server I am uploading to is a Linux box.

Thanks
 
Old April 9th, 2010, 12:03 PM
Registered User
 
Join Date: Apr 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Just a guess, but if it's working when you're logged in and doesn't when you're not...I would look at permissions. Your program may need a user id to run under so that it's able to write the file.

Although, I'm not sure why you just don't use a common FTP program to do this...

Good luck.
 
Old April 9th, 2010, 01:02 PM
Registered User
 
Join Date: Apr 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I was using FileZilla to move the files over, but it is a manual process. I have all the paths of the files set so the idea was, as the files come into the input directory, they are moved automatically to their correct folders.

During testing of the service I am still logged into the workstation. I had the same idea about permissions. That is the strangest part, the only difference in the whole processes of the 2 is that on the GUI I push a button which then runs all the code unattended, and the service which uses a timer to do the same thing.





Similar Threads
Thread Thread Starter Forum Replies Last Post
FTP directly to unix box from macro geniusprachi2003 Pro VB Databases 0 July 16th, 2007 08:18 AM
migrate from unix to windows pmreddy01 Apache Tomcat 0 January 23rd, 2007 04:22 AM
XSLT Windows v's Unix issue fbrody XSLT 1 December 15th, 2006 06:25 AM
Problem in UnInstalling Windows Service pratik28 General .NET 2 May 25th, 2006 03:15 AM
Oracle migration from Windows to Unix vijayma Oracle 1 December 14th, 2004 11:48 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.