суббота, 6 февраля 2021 г.

Sending file to FTP server from VBS script

Sending to FTP and copying the link to the clipboard (Visual Basic Script)



Rem Отправка на FTP и копирование ссылки в буфер (Visual Basic Script)

Dim objArgs, Server, DomainName, Port, User, Pass, Folder, rootFolder, CloseDOS, DosStr

 

'=== Данные учетной записи FTP ===

 

Server = "00.000.000.00"

DomainName = "http://example.com"

Port = "21"

User = "***"

Pass = "***"

 

'Папка на FTP, куда будут складываться файлы

rootFolder = "public_html" 'корневая

Folder = "Forum/Dl" 'подкаталог

 

'Флаг - закрывать консольное окно после передачи данных

CloseDOS = True

if not CloseDOS then DosStr = "&pause"

 

Set objArgs = wscript.Arguments

If objArgs.Count <> 0 Then 'Проверяем аргументы (Drag & Drop "путь к файлу")

    Dim FName, WSHShell, Link, FF, TmpFile, objFile

    

    'Получаем имя файла

    FName = Mid(objArgs(0), InStrRev(objArgs(0), "\") + 1)

    'Интернет-адрес

    Link = DomainName & "/" & Folder & "/" & FName

 

    Set WSHShell = CreateObject("WScript.Shell")

    Set objFSO = CreateObject("Scripting.FileSystemObject")

    

    'Копируем в буфер обмена Windows

    WSHShell.Run "cmd.exe /C <nul set /p ""=" & Link & """ | CLIP", 0, False

 

    'Формируем строку коннекта для утилиты FTP

    TmpFile = WSHShell.ExpandEnvironmentStrings("%temp%") & "\temp_" & CInt(Rnd() * 1000)   

    'ForAppending = 8, ForReading = 1, ForWriting = 2

    Set objFile = objFSO.OpenTextFile (TmpFile, 2, True, 0) 'True - создать файл

        objFile.WriteLine "open " & Server & " " & Port

        objFile.WriteLine User

        objFile.WriteLine Pass

        objFile.WriteLine "cd " & rootFolder & "/" & Folder

        objFile.WriteLine "binary"

        objFile.WriteLine "put """ & objArgs(0) & """"

        objFile.WriteLine "disconnect"

        objFile.WriteLine "bye"

    objFile.Close

    

    'Добавляем утилиту FTP в исключения файрвола и запускаем

    WSHShell.Run "cmd.exe /c ""(netsh firewall add allowedprogram """ & WSHShell.ExpandEnvironmentStrings("%windir%") & _

      "\system32\ftp.exe"" ENABLE& ftp -s:""" & TmpFile & """" & DosStr & ")""", 1, True

 

    objFSO.DeleteFile TmpFile, True

 

    Set WSHShell = Nothing: Set objFile = Nothing: Set objFSO = Nothing

    

    wscript.echo "Путь к файлу на FTP: " & vbLf & Link & String(2, vbLf) & _

    "Путь к файлу скопирован в буфер обмена Windows."

  Else

    wscript.echo "Перетащите файл на VBS-сценарий"

End If

Set objArgs = Nothing

How to list mp3 files with details to Excel

How to list mp3 files with details to Excel.
*iPath variable needs for path with music files for scanning.


Sub CreateReport_Mp3FileProperties()
    Dim iFileName$, iPath$, iRow&, iColumn&
    Dim iFolder As Object, iMp3File As Object
        
    iPath = "C:\Users\Office\Desktop\myfolder\": iRow = 2
    
    Set iFolder = CreateObject("Shell.Application").Namespace(CVar(iPath))
    If Not iFolder Is Nothing Then
       iFileName = Dir(iPath & "*.mp3")
       If iFileName <> "" Then
          Workbooks.Add xlWBATWorksheet
          Application.ScreenUpdating = False
          Do
               Application.StatusBar = iFileName
               Set iMp3File = iFolder.ParseName(iFileName)
               For iColumn = 0 To 50 '
                   Cells(iRow, iColumn + 1) = iFolder.GetDetailsOf(iMp3File, iColumn)
               Next
               iFileName = Dir
               iRow = iRow + 1
          Loop While iFileName <> ""
          For iColumn = 0 To 50 ' Headers Report
              Cells(1, iColumn + 1) = iFolder.GetDetailsOf(iFolder.Items, iColumn)
          Next
          Application.StatusBar = False
          Application.ScreenUpdating = True
       Else
          MsgBox "No files .mp3", , ""
       End If
    Else
       MsgBox "Folder doesn't exist", , ""
    End If
End Sub

Постоянные читатели

Популярные сообщения