简体   繁体   English

如何使用Perl将文件从Unix目录复制到Windows目录?

[英]How to copy a file from Unix directory to a Windows directory using Perl?

I'm new to Perl and trying to copy a CSV file from UNIX directory to a Windows shared drive, without using FTP. 我是Perl的新手,并尝试将CS​​V文件从UNIX目录复制到Windows共享驱动器,而不使用FTP。

Below is my code, in which the source is a CSV file in UNIX directory, whilst "C:/New folder" has been created to receive the file. 下面是我的代码,其中的源是UNIX目录中的CSV文件,而已创建"C:/New folder"来接收该文件。 I put the new folder here as a placeholder as I haven't figured out which shared drive should be used. 我将新文件夹放在此处作为占位符,因为我没有弄清楚应该使用哪个共享驱动器。

use File::Copy;

sub TestCopyFile
{
    my $source = "/home/user/somefolder/somefile.csv";
    my $target = "C:/New folder";

    copy($source, $target);
}

So when I tried to run this from PuTTY, I've been told it is successful. 因此,当我尝试从PuTTY运行此程序时,被告知它是成功的。 However, I couldn't find the file in the target folder. 但是,我在目标文件夹中找不到该文件。

Is there anything wrong with my code? 我的代码有什么问题吗? Any suggestion is appreciated. 任何建议表示赞赏。

Not a question, really. 确实不是一个问题。 Windows shared drive means SMB . Windows共享驱动器表示SMB You need to install and mount the shared drive into your local file system tree. 您需要安装并将共享驱动器安装到本地文件系统树中。

Example: mount.cifs //the-workstation/the-share ~/mnt/the-workstation/the-share -o rw,vers=3.0,sec=ntlmssp,credentials=$HOME/.smbcredentials,cache=strict,uid=1000,forceuid,gid=100,forcegid,addr=172.xxx.xxx.xxx,file_mode=0644,dir_mode=0755,nounix,serverino,rsize=1048576,wsize=1048576,actimeo=1 示例: mount.cifs //the-workstation/the-share ~/mnt/the-workstation/the-share -o rw,vers=3.0,sec=ntlmssp,credentials=$HOME/.smbcredentials,cache=strict,uid=1000,forceuid,gid=100,forcegid,addr=172.xxx.xxx.xxx,file_mode=0644,dir_mode=0755,nounix,serverino,rsize=1048576,wsize=1048576,actimeo=1

If that's too difficult to figure out in the beginning, you can browse the network with smb4k . 如果一开始很难弄清楚,可以使用smb4k浏览网络。 Once you have found the correct share, it will tell you the appropriate command for mounting. 找到正确的共享后,它将告诉您适当的安装命令。

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

相关问题 如何放置Unix命令-在VBScript中将文件从Windows复制到Unix目录/从Unix复制到Windows? - How to place unix commands - copy files from Windows to Unix directory/ Unix to Windows in VBScript? Windows-使用Perl监视目录以查找新文件的放置/创建 - Windows - Using perl monitor a directory for a new file drop/creation Perl File::Find Windows 反斜杠目录路径 - Perl File::Find Windows Backslashes Directory Path Perl DBD :: CSV Windows上没有这样的文件或目录 - Perl DBD::CSV No such file or directory on Windows 如何编写Windows批处理脚本,将最新文件从目录复制到新文件夹? - How do I write a Windows batch script to copy the newest file from a directory into new folder? 从Windows中的远程位置复制目录 - Copy a directory from remote location in windows 如何使用批处理文件中的目录通配符移动或复制文件夹? - How to Move or Copy Folders using directory Wildcards within Batch File? 从批处理文件的目录中复制文件 - Copy file from batch file's directory 如何使用 Rust 找到 Windows 上的临时目录? (类似于类 Unix 上的 /tmp) - How can I find the temporary directory on Windows using Rust? (Like /tmp on Unix-like) 在Windows上使用Perl在名称长度超过220个字符的目录中创建文件 - Creating a file using Perl on Windows in a directory the length of whose name exceeds 220 characters
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM