[英]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的新手,并尝试将CSV文件从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 perl question, really. 确实不是一个perl问题。 Windows shared drive means SMB .
Windows共享驱动器表示SMB 。 You need to install samba and mount the shared drive into your local file system tree.
您需要安装samba并将共享驱动器安装到本地文件系统树中。
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.