Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
On Linux, there is inotify, which can be used to implement this in a couple of lines. and, it seems, there are interfaces to this either, in the form of system utilities. on Windows, probably, these are some kind of hooks
On PowerShell (default on Win 7), it's something like this ( scrape in the bottom of the barrel and stupidly in the forehead , so it's better to test :) ):
We use two dotnet classes - System.IO.FileSystemWatcher and System.Net.WebClient.
Subscribe to acc. FS events, we get the file name from the event details and upload it using WebClient. The WebClient is smart and can be easily converted to SFTP later.
#
# Watch for files in $watchDir that a match a filer $watchFilter
# and upload them to FTP $ftpUrl when they are changed (modified)
#
$ftpUrl = "ftp://username:[email protected]/pub/incoming/"
$watchDir = "b:\temp"
$watchFilter = "*.txt"
function uploadFile($fullFileName)
{
$webclient = New-Object System.Net.WebClient
$fileName = [system.io.path]::GetFileName($fullFileName)
$fileUrl = $ftpUrl+$fileName
$uri = New-Object System.Uri($fileUrl)
try
{
$rc = $webclient.UploadFile($uri, $fullFileName)
}
catch [System.Net.WebException]
{
Write-Host "[ERR]: "$_
return
}
Write-Host "Uploaded $fullFileName"
}
$watcher = New-object System.IO.FileSystemWatcher $watchDir
$watcher.EnableRaisingEvents = $true
$watcher.Filter = $watchFilter
$changed = Register-ObjectEvent $watcher "Changed" -Action {
Write-Host $eventArgs.ChangeType, $eventArgs.Fullpath
uploadFile $eventArgs.Fullpath
}
while($true) {
echo "."
start-sleep -s 5
}
# EOF
nnCron + scripts (cmd/python/autoit/...) + console ftp client
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question