Connecting Tech Pros Worldwide Forums | Help | Site Map

FTP loading in Windows Service

=?Utf-8?B?Um9iZXJ0?=
Guest
 
Posts: n/a
#1: Sep 25 '07
I will try to explain the problem.
I'm doing an asynchronous copy file from local station to my FTP according
to the MSDN example:
http://msdn2.microsoft.com/en-us/lib...st(VS.80).aspx

see the 3-rd example ("The following code example demonstrates using
asynchronous operations to upload a file to an FTP server.")

In the main part of my service I use System.Threading.Timer.

After files copied they should be moved from one folder to another.

But the system crashes after files copied to FTP when I try any operation
with file which is already sent to ftp.
So, it's blocked, locked or whatever.

I close all streams and tried stream.Lock/Unlock.

But still the problem exists.

When I place the same code, with the same Threading Timer inside non-service
project, just WinForm, it works fine, but under the Service doesn't.

Could you give me any clue, please?


Nicholas Paldino [.NET/C# MVP]
Guest
 
Posts: n/a
#2: Sep 25 '07

re: FTP loading in Windows Service


Robert,

Well, you didn't show any code, and you didn't show any details of the
exception. Could you provide some of those? It would help.


--
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com

"Robert" <Robert@discussions.microsoft.comwrote in message
news:463B8414-F7D1-4EC0-880B-762F2EF9859B@microsoft.com...
Quote:
>I will try to explain the problem.
I'm doing an asynchronous copy file from local station to my FTP according
to the MSDN example:
http://msdn2.microsoft.com/en-us/lib...st(VS.80).aspx
>
see the 3-rd example ("The following code example demonstrates using
asynchronous operations to upload a file to an FTP server.")
>
In the main part of my service I use System.Threading.Timer.
>
After files copied they should be moved from one folder to another.
>
But the system crashes after files copied to FTP when I try any operation
with file which is already sent to ftp.
So, it's blocked, locked or whatever.
>
I close all streams and tried stream.Lock/Unlock.
>
But still the problem exists.
>
When I place the same code, with the same Threading Timer inside
non-service
project, just WinForm, it works fine, but under the Service doesn't.
>
Could you give me any clue, please?
>

=?Utf-8?B?Um9iZXJ0?=
Guest
 
Posts: n/a
#3: Sep 25 '07

re: FTP loading in Windows Service


Nicolas,
The exception is:
UnauthorizedAccessException

Timer in the main service body is from System.Threading library.

The example link I mentioned is the code.

Inside timer callback after files transfered I just move files from Folder1
to Folder2.

The FTP transfer goes fast, actually there are just 2 files only for now.

I can see them inside remote folder... but Ftp request blocks them only if I
use this code inside service.

As I mentioned before if placed in standalone aplication - works fine.


=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
 
Posts: n/a
#4: Sep 25 '07

re: FTP loading in Windows Service


Services by default run under account credentials that are not highly
privileged. You can change the account that your service runs under to one
that has the requested permissions on the remote machine.
-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com



"Robert" wrote:
Quote:
Nicolas,
The exception is:
UnauthorizedAccessException
>
Timer in the main service body is from System.Threading library.
>
The example link I mentioned is the code.
>
Inside timer callback after files transfered I just move files from Folder1
to Folder2.
>
The FTP transfer goes fast, actually there are just 2 files only for now.
>
I can see them inside remote folder... but Ftp request blocks them only if I
use this code inside service.
>
As I mentioned before if placed in standalone aplication - works fine.
>
>
=?Utf-8?B?Um9iZXJ0?=
Guest
 
Posts: n/a
#5: Sep 25 '07

re: FTP loading in Windows Service


Peter,

Here is the code snap where the exception is:

public void GlobalTick_Tick(Object stateInfo)

{
Action act = new Action(); <--FTP transfer here Ok
string from = "FolderFrom&File"; <= One of the transfered
files (LocalPC)
string where = "FolderTo&File";<= (local PC)
if (File.Exists(from) && !File.Exists(where))
{
Logger.Record("Moved from: " + from + " To: " + where);
try
{
File.SetAttributes(from, FileAttributes.Normal);<--
here's the Exception
File.Copy(from, where);<-- here's the Exception
File.Delete(from);<-- here's the Exception

}
catch (UnauthorizedAccessException ex)
{
throw ex;
}
}
}

Files are blocked for FTP request, though I close request stream and file
stream, and even I lock and unlock the file stream during FTP transfer, and
Timer doesn't come to that point yet.....as the transfer itself takes only 2
seconds and timer set up for every 10 seconds.

How to set up the credentials for remote? I use the right username and
password to login the FTP server folder, and I see how files are moved there.

Anything I lost? Please, clearify the idea.

Thanks

Closed Thread


Similar C# / C Sharp bytes