By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,314 Members | 1,772 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,314 IT Pros & Developers. It's quick & easy.

Simple ftp service

P: n/a
Hey,

I have following simple ftpService class with a method download.
When I run the class not as a web service it works fine.
But when I run the class as a web service the FtpGetFile() method
fails.
I guess the reason is that I try to save a file locally, what is maybe not
allowed with in a web service.

Has anybody an idea?

Thanks a lot.

Ahoi
Maik Thiele

code:
-----

Imports System.Web.Services
<WebService(Namespace:="http://tempuri.org/")> _
Public Class ftpService
Inherits System.Web.Services.WebService

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

<WebMethod()> Public Function Download(ByVal ftphost As String, ByVal
filename As String, _
ByVal port As Integer, ByVal login As String, ByVal pwd As String) As String

Dim INet, INetConn As Integer
Dim RC As Boolean
INet = InternetOpen("FTP Connection", 1, vbNullString, vbNullString, 0)
INetConn = InternetConnect(INet, ftphost, port, login, pwd, 1, 0, 0)
RC = FtpGetFile(INetConn, filename, "C:\newfile.txt", False, 1, 0, 0)
InternetCloseHandle(INetConn)
InternetCloseHandle(INet)
if RC then
Return "successful"
else
Return"failed"
end if
End Function
End Class
Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
This is probably a simple ACL issue. Make sure you give the user that your
IIS/ASP.NET is running as rights to write to your directory. I had this
issue once and I resolved it by doing this.

Eric

--
Eric Cherng
MCP, MCDBA, MCSD
http://echerng.com
"Maik Thiele" <mt******@inf.tu-dresden.de> wrote in message
news:2o************@uni-berlin.de...
Hey,

I have following simple ftpService class with a method download.
When I run the class not as a web service it works fine.
But when I run the class as a web service the FtpGetFile() method
fails.
I guess the reason is that I try to save a file locally, what is maybe not
allowed with in a web service.

Has anybody an idea?

Thanks a lot.

Ahoi
Maik Thiele

code:
-----

Imports System.Web.Services
<WebService(Namespace:="http://tempuri.org/")> _
Public Class ftpService
Inherits System.Web.Services.WebService

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

<WebMethod()> Public Function Download(ByVal ftphost As String, ByVal
filename As String, _
ByVal port As Integer, ByVal login As String, ByVal pwd As String) As
String

Dim INet, INetConn As Integer
Dim RC As Boolean
INet = InternetOpen("FTP Connection", 1, vbNullString, vbNullString, 0)
INetConn = InternetConnect(INet, ftphost, port, login, pwd, 1, 0, 0)
RC = FtpGetFile(INetConn, filename, "C:\newfile.txt", False, 1, 0, 0)
InternetCloseHandle(INetConn)
InternetCloseHandle(INet)
if RC then
Return "successful"
else
Return"failed"
end if
End Function
End Class

Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.