Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1.  
  2.  
  3. #Directory where to find pictures to upload
  4. $Dir= 'D:\down\1\'
  5.  
  6. #Directory where to save uploaded pictures
  7. $saveDir = 'D:\down\2\'
  8.  
  9. #ftp server params
  10. $ftp = 'ftp://83.149.126.129/'
  11. $user = 'adult'
  12. $pass = 'eboti3'
  13.  
  14. #Connect to ftp webclient
  15. $webclient = New-Object System.Net.WebClient
  16. $webclient.Credentials = New-Object System.Net.NetworkCredential($user,$pass)
  17.  
  18. #Initialize var for infinite loop
  19. $i=0
  20.  
  21. #Infinite loop
  22. while($i -eq 0){
  23.  
  24. #Pause 1 seconde before continue
  25. Start-Sleep -sec 1
  26.  
  27. #Search for pictures in directory
  28. foreach($item in (dir $Dir "*.jpg"))
  29. {
  30. #Set default network status to 1
  31. $onNetwork = "1"
  32.  
  33. #Get picture creation dateTime...
  34. $pictureDateTime = (Get-ChildItem $item.fullName).CreationTime
  35.  
  36. #Convert dateTime to timeStamp
  37. $pictureTimeStamp = (Get-Date $pictureDateTime).ToFileTime()
  38.  
  39. #Get actual timeStamp
  40. $timeStamp = (Get-Date).ToFileTime()
  41.  
  42. #Get picture lifeTime
  43. $pictureLifeTime = $timeStamp - $pictureTimeStamp
  44.  
  45. #We only treat pictures that are fully written on the disk
  46. #So, we put a 2 second delay to ensure even big pictures have been fully wirtten in the disk
  47. if($pictureLifeTime -gt "2") {
  48.  
  49. #If upload fails, we set network status at 0
  50. try{
  51.  
  52. $uri = New-Object System.Uri($ftp+$item.Name)
  53.  
  54. $webclient.UploadFile($uri, $item.FullName)
  55.  
  56. } catch [Exception] {
  57.  
  58. $onNetwork = "0"
  59. write-host $_.Exception.Message;
  60. }
  61.  
  62. #If upload succeeded, we do further actions
  63. if($onNetwork -eq "1"){
  64. "Copying $item..."
  65. Copy-Item -path $item.fullName -destination $saveDir$item
  66.  
  67. "Deleting $item..."
  68. Remove-Item $item.fullName
  69. }
  70.  
  71.  
  72. }
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement