简体   繁体   English

尝试使用来自 PS 中的 nitado 服务器的文件掩码 ftp 一些文件,我错过了什么吗?

[英]Trying to ftp some files using filemask from nitrado server in PS, am I missing something?

I have the following in a ps1 script and I am connecting over ftp using winscp to a nitrado server with the goal of copying the folder called backups and the contents over to my pc.我在 ps1 脚本中有以下内容,我正在使用 winscp 通过 ftp 连接到 nitado 服务器,目的是将名为备份的文件夹和内容复制到我的电脑上。 The issue I face is when I run the following it just returns the whole of the minecraftbukkit folder almost as if it ignores the mask other than '*' and just returns it all.我面临的问题是,当我运行以下命令时,它只会返回整个 minecraftbukkit 文件夹,几乎就像它忽略了除“*”以外的掩码并返回所有内容一样。 I have tried using a mask of "backups/" however this then returns nothing and in the log output it says File "/minecraftbukkit" excluded from transfer.我曾尝试使用"backups/"的掩码,但是这随后什么也不返回,并且在日志输出中它说文件“/minecraftbukkit”从传输中排除。

I have tried this on my personal linux server and it seemed to work so is this some issue based on the nitrado service?我已经在我的个人 linux 服务器上尝试过这个,它似乎可以工作,所以这是基于 nitado 服务的一些问题吗? or possibly their linux server is missing a feature that is needed or something.或者可能他们的 linux 服务器缺少所需的功能或其他东西。 I am open to any suggestions on how to make this work as intended.我愿意接受有关如何按预期进行这项工作的任何建议。 Thanks in advance.提前致谢。

try
{
    # Load WinSCP .NET assembly
     Add-Type -Path "D:\Users\username\Downloads\Minecraft stuff\Scripts\WinSCPnet.dll"
    
    $folderPath = 'D:\Users\username\Downloads\Minecraft stuff\test'
    $folderPath2 = '/minecraftbukkit'
    
    # Session.FileTransferProgress event handler
    
    function FileTransferProgress
    {
        param($e)
 
        # New line for every new file
        if (($script:lastFileName -ne $Null) -and
            ($script:lastFileName -ne $e.FileName))
        {
            Write-Host
        }
 
        # Print transfer progress
        Write-Host -NoNewline ("`r{0} ({1:P0})" -f $e.FileName, $e.FileProgress)
 
        # Remember a name of the last file reported
        $script:lastFileName = $e.FileName
    }

    $script:lastFileName = $Null
    
    # Setup session options
    $sessionOptions = New-Object WinSCP.SessionOptions -Property @{
        Protocol = [WinSCP.Protocol]::ftp
        HostName = "hostname"
        PortNumber = 21
        UserName = "username"
        Password = "password"
    }
 
    $session = New-Object WinSCP.Session

    try
    {
        # Will continuously report progress of transfer
        $session.add_FileTransferProgress( { FileTransferProgress($_) } )
        $session.SessionLogPath = "sessionlog.txt"
        # Connect
        $session.Open($sessionOptions)

        # Upload files
        $transferOptions = New-Object WinSCP.TransferOptions
        $transferOptions.TransferMode = [WinSCP.TransferMode]::Binary
        $transferOptions.FileMask = "backups/"
 
        [array]$transferResult += $session.GetFiles($folderPath2, $folderPath , $False, $transferOptions)
        
        # Throw on any error
        $transferResult.Check()
 
        # Print results
        foreach ($transfer in $transferResult.Transfers)
        {
            Write-Host "Upload of $($transfer.FileName) succeeded"
        }

        foreach ($transfer in $transferResult.Failures)
        {
            Write-Host "Upload of $($transfer.FileName) Failed"
        }
    }
    finally
    {
        # Disconnect, clean up
        $session.Dispose()
    }
 
    exit 0
}
catch
{
    Write-Host "Error: $($_.Exception.Message)"
    exit 1
}

Log (omitted beginning and usernames for privacy):日志(为了隐私,省略了开头和用户名):

--------------------------------------------------------------------------
< 2021-11-16 12:04:38.845 230 User logged in
> 2021-11-16 12:04:38.845 SYST
< 2021-11-16 12:04:38.860 215 UNIX Type: L8
> 2021-11-16 12:04:38.860 FEAT
< 2021-11-16 12:04:38.874 211-Features:
< 2021-11-16 12:04:38.874  AUTH TLS
< 2021-11-16 12:04:38.874  CCC
< 2021-11-16 12:04:38.875  CLNT
< 2021-11-16 12:04:38.875  EPRT
< 2021-11-16 12:04:38.875  EPSV
< 2021-11-16 12:04:38.875  HOST
< 2021-11-16 12:04:38.875  LANG zh-CN;zh-TW;bg-BG;en-US;es-ES;fr-FR;it-IT;ja-JP;ko-KR;ru-RU
< 2021-11-16 12:04:38.875  MDTM
< 2021-11-16 12:04:38.875  MFF modify;UNIX.group;UNIX.mode;
< 2021-11-16 12:04:38.875  MFMT
< 2021-11-16 12:04:38.875  MLST modify*;perm*;size*;type*;unique*;UNIX.group*;UNIX.groupname*;UNIX.mode*;UNIX.owner*;UNIX.ownername*;
< 2021-11-16 12:04:38.875  PBSZ
< 2021-11-16 12:04:38.875  PROT
< 2021-11-16 12:04:38.876  REST STREAM
< 2021-11-16 12:04:38.876  SIZE
< 2021-11-16 12:04:38.876  SSCN
< 2021-11-16 12:04:38.876  TVFS
< 2021-11-16 12:04:38.876  UTF8
< 2021-11-16 12:04:38.876 211 End
> 2021-11-16 12:04:38.876 CLNT WinSCP-release-5.19.2
< 2021-11-16 12:04:38.891 200 OK
> 2021-11-16 12:04:38.891 OPTS UTF8 ON
< 2021-11-16 12:04:38.909 200 UTF8 set to on
< 2021-11-16 12:04:38.909 Script: Connected
. 2021-11-16 12:04:38.910 Connected
. 2021-11-16 12:04:38.910 --------------------------------------------------------------------------
. 2021-11-16 12:04:38.910 Using FTP protocol.
. 2021-11-16 12:04:38.910 Doing startup conversation with host.
< 2021-11-16 12:04:38.910 Script: Starting the session...
> 2021-11-16 12:04:38.910 PWD
< 2021-11-16 12:04:38.923 257 "/" is the current directory
. 2021-11-16 12:04:38.924 Getting current directory name.
. 2021-11-16 12:04:38.924 Startup conversation with host finished.
< 2021-11-16 12:04:38.924 Script: Session started.
< 2021-11-16 12:04:38.924 Script: Active session: [1] 
> 2021-11-16 12:04:39.643 Script: pwd
< 2021-11-16 12:04:39.644 Script: /
> 2021-11-16 12:04:39.716 Script: get  -nopermissions -preservetime -transfer="binary" -filemask="backups/"  -- "/minecraftbukkit" "D:\Users\username\Downloads\Minecraft stuff\test"
. 2021-11-16 12:04:39.716 Listing file "/minecraftbukkit".
. 2021-11-16 12:04:39.717 Retrieving file information...
> 2021-11-16 12:04:39.717 MLST /minecraftbukkit
< 2021-11-16 12:04:39.731 250-Start of list for /minecraftbukkit
< 2021-11-16 12:04:39.732  modify=20211112092756;perm=flcdmpe;type=dir;unique=10304U4064951C;UNIX.group=11257;UNIX.groupname=11257;UNIX.mode=0700;UNIX.owner=6258;UNIX.ownername=; /minecraftbukkit
< 2021-11-16 12:04:39.732 250 End of list
. 2021-11-16 12:04:39.732  modify=20211112092756;perm=flcdmpe;type=dir;unique=10304U4064951C;UNIX.group=11257;UNIX.groupname=11257;UNIX.mode=0700;UNIX.owner=6258;UNIX.ownername=; /minecraftbukkit
. 2021-11-16 12:04:39.732 Retrieving file information successful
. 2021-11-16 12:04:39.733 minecraftbukkit;D;0;2021-11-12T09:27:56.000Z;3;"" [0];"11257" [0];rwx------;0
. 2021-11-16 12:04:39.733 Copying 1 files/directories to local directory "D:\Users\username\Downloads\Minecraft stuff\" - total size: 0
. 2021-11-16 12:04:39.733   PrTime: Yes; PrRO: No; Rght: rw-r--r--; PrR: No (No); FnCs: N; RIC: 0100; Resume: S (102400); CalcS: Yes; Mask: test
. 2021-11-16 12:04:39.733   TM: B; ClAr: No; RemEOF: No; RemBOM: No; CPS: 0; NewerOnly: No; EncryptNewFiles: Yes; ExcludeHiddenFiles: No; ExcludeEmptyDirectories: No; InclM: backups/; ResumeL: 0
. 2021-11-16 12:04:39.733   AscM: *.*html; *.htm; *.txt; *.php; *.php3; *.cgi; *.c; *.cpp; *.h; *.pas; *.bas; *.tex; *.pl; *.js; .htaccess; *.xtml; *.css; *.cfg; *.ini; *.sh; *.xml
. 2021-11-16 12:04:39.733 File "/minecraftbukkit" excluded from transfer
* 2021-11-16 12:04:39.733 (ESkipFile) 
. 2021-11-16 12:04:39.733 Copying finished: Transferred: 0, Elapsed: 0:00:00, CPS: 0/s
> 2021-11-16 12:04:39.826 Script: exit
. 2021-11-16 12:04:39.826 Script: Exit code: 0
. 2021-11-16 12:04:39.830 Disconnected from server

In terms of folder structure this is it just a regular bukkit layout and I am trying to pull the backups folder as shown:就文件夹结构而言,这只是一个常规的 bukkit 布局,我正在尝试拉备份文件夹,如图所示:

在此处输入图片说明

If you want to download backups specifically, do it explicitly:如果您想专门下载backups ,请明确执行:

$folderPath2 = '/minecraftbukkit/backups/*'

If you point was to make the "filemask" variable, your problem is that your are giving WinSCP conflicting masks.如果您要创建“filemask”变量,那么您的问题是您提供了 WinSCP 冲突掩码。 You are telling it to download everything that has name minecraftbukkit and backups at the same time.您告诉它同时下载所有名称为minecraftbukkitbackups的内容。 So it does not download anything.所以它不会下载任何东西。

If you want to tell WinSCP to apply the mask to files in minecraftbukkit and not to the minecraftbukkit directly, you need to add a slash to the path.如果您想告诉 WinSCP 将掩码应用于minecraftbukkit文件而不是直接应用于minecraftbukkit ,则需要在路径中添加斜杠。 Or to make it even more obvious, add /* :或者为了让它更明显,添加/*

$folderPath2 = '/minecraftbukkit/*'

As the documentation for theremotePath parameter says:正如remotePath参数的文档所说:

Full path to remote directory followed by slash and wildcard to select files or subdirectories to download.远程目录的完整路径,后跟斜杠和通配符以选择要下载的文件或子目录。 To download all files in a directory, use mask * .要下载目录中的所有文件,请使用 mask *

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我正在尝试使用 PS 脚本自动配置 SQL Server 2016 和 2019 上的 TCPPort 编号 1433 - I am trying to automate the config of TCPPort number 1433 on SQL Server 2016 and 2019 with a PS script Powershell ScriptBlock 关闭:我错过了什么吗? - Powershell ScriptBlock closure: am I missing something? 我在Azure Powershell(发布管道)中运行的Powershell脚本中根本缺少一些东西吗? - Is there something I am fundamentally missing from this powershell script I am running in Azure Powershell (release pipeline)? 为什么我的PS New-ADUser脚本中出现“缺少表达式”错误? - Why am I getting a “missing expression” error in my PS New-ADUser script? 从 FTP 服务器拉文件不是基于文件日期创建目录 - Pulling files from FTP server is not creating directory based on files date 尝试递归从ftp下载特定文件并在它们上运行命令 - trying to download specific files from ftp recursively and run a command on them 使用 powershell 将文件上传到 FTP 服务器 - Upload files to an FTP Server using powershell 使用PowerShell从FTP服务器删除文件 - Deleting file from FTP server using PowerShell 从FTP服务器递归下载文件 - Recursively downloading files from FTP server 如何使用 PowerShell 的 FtpWebRequest 类从 FTP 服务器下载文件名中包含井号/哈希符号“#”的文件 - How to download files that contain a pound/hash sign '#' in the filename from an FTP server using PowerShell's FtpWebRequest class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM