- 浏览: 86374 次
- 性别:
- 来自: 上海
文章分类
最新评论
samba安装:
检查安装了samba:rpm -qa | grep samba
在光盘(redhat系统安装盘)中查找samba的rpm文件路径:[root@yangfan /]# find -name samba*
按顺序安装samba的rpm文件:
[root@yangfan Packages]# rpm -ivh samba-3.5.10-125.el6.x86_64.rpm
warning: samba-3.5.10-125.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
error: Failed dependencies:
samba-common = 0:3.5.10-125.el6 is needed by samba-0:3.5.10-125.el6.x86_64
[root@yangfan Packages]# find -name samba*
find: paths must precede expression: samba4-libs-4.0.0-23.alpha11.el6.i686.rpm
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
[root@yangfan Packages]# rpm -ivh samba-common-3.5.10-125.el6.x86_64.rpm
warning: samba-common-3.5.10-125.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing... ########################################### [100%]
1:samba-common ########################################### [100%]
[root@yangfan Packages]# rpm -ivh samba-3.5.10-125.el6.x86_64.rpm
warning: samba-3.5.10-125.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing... ########################################### [100%]
1:samba ########################################### [100%]
[root@yangfan Packages]# rpm -ivh samba-client-3.5.10-125.el6.x86_64.rpm
warning: samba-client-3.5.10-125.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing... ########################################### [100%]
1:samba-client ########################################### [100%]
[root@yangfan Packages]#
启动samba:service smb start
重行运行Linux Samba:终端运行命令 service smb restart
关闭samba:
[root@yangfan /]# service smb stop
Shutting down SMB services: [ OK ]
关闭防火墙:iptables -F
添加一个samba账号://注意bill必须是已经存在的linux账号
[root@yangfan /]# smbpasswd -a bill
New SMB password:billsmb
Retype new SMB password:billsmb
Added user bill.
不能在共享目录创建文件解决方法:
/etc/selinux/config中修改
#SELINUX=enforcing
SELINUX=disabled
Windows访问Linux共享文件(夹):
检查安装了samba:rpm -qa | grep samba
在光盘(redhat系统安装盘)中查找samba的rpm文件路径:[root@yangfan /]# find -name samba*
按顺序安装samba的rpm文件:
[root@yangfan Packages]# rpm -ivh samba-3.5.10-125.el6.x86_64.rpm
warning: samba-3.5.10-125.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
error: Failed dependencies:
samba-common = 0:3.5.10-125.el6 is needed by samba-0:3.5.10-125.el6.x86_64
[root@yangfan Packages]# find -name samba*
find: paths must precede expression: samba4-libs-4.0.0-23.alpha11.el6.i686.rpm
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
[root@yangfan Packages]# rpm -ivh samba-common-3.5.10-125.el6.x86_64.rpm
warning: samba-common-3.5.10-125.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing... ########################################### [100%]
1:samba-common ########################################### [100%]
[root@yangfan Packages]# rpm -ivh samba-3.5.10-125.el6.x86_64.rpm
warning: samba-3.5.10-125.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing... ########################################### [100%]
1:samba ########################################### [100%]
[root@yangfan Packages]# rpm -ivh samba-client-3.5.10-125.el6.x86_64.rpm
warning: samba-client-3.5.10-125.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing... ########################################### [100%]
1:samba-client ########################################### [100%]
[root@yangfan Packages]#
启动samba:service smb start
重行运行Linux Samba:终端运行命令 service smb restart
关闭samba:
[root@yangfan /]# service smb stop
Shutting down SMB services: [ OK ]
关闭防火墙:iptables -F
添加一个samba账号://注意bill必须是已经存在的linux账号
[root@yangfan /]# smbpasswd -a bill
New SMB password:billsmb
Retype new SMB password:billsmb
Added user bill.
不能在共享目录创建文件解决方法:
/etc/selinux/config中修改
#SELINUX=enforcing
SELINUX=disabled
Windows访问Linux共享文件(夹):
package d20130401; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.MalformedURLException; import java.net.UnknownHostException; import java.util.Date; import org.omg.PortableInterceptor.SUCCESSFUL; import jcifs.smb.SmbException; import jcifs.smb.SmbFile; import jcifs.smb.SmbFileInputStream; import jcifs.smb.SmbFileOutputStream; //jar package can get from attachment file public class RemoteShareFile { public static void main(String[] args) { String smbUrls = "smb://username:password@computername/opt/webhost/pn/etc/pn.conf"; smbUrls = "smb://ASIAPACIFIC;username:password@computerIp/share/";//GetComputerAddress/PnSnapshotPerformanceTest smbUrls = "smb://bill:billsmb@computerIp/bill_share/GetComputerAddress.java"; String localPath = "C:/bill/testShare"; localPath = "C:/bill/testShare"; //File file = readFromSmb(smbMachine, localPath); //readFileFromSever(smbUrls, localPath); Date startDate = new Date(); smbUrls = "smb://bill:billsmb@16.187.25.106/bill_share"; localPath = "C:/bill/share/RemoteShareFile.java"; boolean writeFileSuccess = writeFileToServer(smbUrls, localPath); System.out.println("Write file to server is success? " + writeFileSuccess); Date endDate = new Date(); long useMillisecond = endDate.getTime() - startDate.getTime(); System.out.println("Use millisecond: " + useMillisecond); System.out.println("Use second: " + useMillisecond/1000); System.out.println(); startDate = new Date(); //smbUrls = "smb://bill:billsmb@16.187.25.106/bill_share"; localPath = "C:/bill/share/XXXXXX_XXXXXXXXXX_2013_03_26_23_04_08_951.xml"; writeFileSuccess = writeFileToServer(smbUrls, localPath); System.out.println("Write file to server is success? " + writeFileSuccess); endDate = new Date(); useMillisecond = endDate.getTime() - startDate.getTime(); System.out.println("Use millisecond: " + useMillisecond); System.out.println("Use second: " + useMillisecond/1000); System.out.println("\n-------- Create folder -----------"); startDate = new Date(); //smbUrls = "smb://bill:billsmb@16.187.25.106/bill_share"; localPath = "C:/bill/share/test"; writeFileSuccess = writeFileToServer(smbUrls, localPath); System.out.println("Write file to server is success? " + writeFileSuccess); endDate = new Date(); useMillisecond = endDate.getTime() - startDate.getTime(); System.out.println("Use millisecond: " + useMillisecond); System.out.println("Use second: " + useMillisecond/1000); } private static boolean writeFileToServer(String smbUrls, String localPath) { Boolean writeFileSuccess = null; InputStream is = null; OutputStream os = null; try { File localFile = new File(localPath); String fileName = localFile.getName(); System.out.println(fileName + " is a directory? " + localFile.isDirectory()); System.out.println(fileName + "'s length is: " + localFile.length()); /*SmbFile smbFile = null; if (localFile.isDirectory()) { smbFile = new SmbFile(smbUrls + "/" + fileName + "/"); } else { smbFile = new SmbFile(smbUrls + "/" + fileName); }*/ SmbFile smbFile = new SmbFile(smbUrls + "/" + fileName); if (localFile.isDirectory()) { if (!smbFile.exists()) { smbFile.mkdir(); System.out.println("Create romote folder successfully: " + smbFile.getURL()); } else { System.out.println("Create romote folder successfully: " + smbFile.getURL()); } return true; } is = new BufferedInputStream(new FileInputStream(localFile)); os = new BufferedOutputStream(new SmbFileOutputStream(smbFile)); byte[] buffer = new byte[1024]; int n; while((n = is.read(buffer)) != -1) { os.write(buffer, 0, n); } writeFileSuccess = true; } catch (MalformedURLException e) { System.err.println("------------- Create samba file fail ------------------"); e.printStackTrace(); } catch (FileNotFoundException e) { System.err.println("------------- File not found ------------------"); e.printStackTrace(); } catch (SmbException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (UnknownHostException e) { System.err.println("------------- Samba file not found ------------------"); e.printStackTrace(); } catch (IOException e) { System.err.println("------------- Read file fail ------------------"); e.printStackTrace(); } finally { if (writeFileSuccess == null) { writeFileSuccess = false; } if (is != null) { try { is.close(); } catch (IOException e) { System.err.println("------------- Close input stream fail ------------------"); } } if (os != null) { try { os.close(); } catch (IOException e) { System.err.println("------------- Close output stream fail ------------------"); } } } return writeFileSuccess; } private static File readFileFromSever(String smbUrls, String localPath) { File localFile = null; InputStream is = null; OutputStream os = null; try { SmbFile smbFile = new SmbFile(smbUrls); System.out.println("smbFile is directory: " + smbFile.isDirectory()); /*if (smbFile.isDirectory()) { String[] smbFileNameArr = smbFile.list(); System.out.println("----------- smbFile.list() -----------"); for (String per : smbFileNameArr) { System.out.println(per); } SmbFile[] smbFileArr = smbFile.listFiles(); System.out.println("----------- smbFile.list() -----------"); for (SmbFile per : smbFileArr) { System.out.println(per.getName()); } } if (true) { return null; }*/ String fileName = smbFile.getName(); is = new BufferedInputStream(new SmbFileInputStream(smbFile)); localFile = new File(localPath + File.separator + fileName); os = new BufferedOutputStream(new FileOutputStream(localFile)); byte[] buffer = new byte[1024]; int n; while((n = is.read(buffer)) != -1) { os.write(buffer, 0, n); } /*byte[] buffer = new byte[smbFile.getContentLength()]; is.read(buffer); os.write(buffer);*/ System.out.println("-------------- end -------------"); } catch (MalformedURLException e) { System.err.println("------------- Create sever message block file fail ------------------"); e.printStackTrace(); } catch (SmbException e) { System.err.println("------------- Create sever message block file input stream fail ------------------"); e.printStackTrace(); } catch (UnknownHostException e) { System.err.println("------------- Create sever message block file input stream fail ------------------"); e.printStackTrace(); } catch (FileNotFoundException e) { System.err.println("------------- Create local file output stream fail ------------------"); e.printStackTrace(); } catch (IOException e) { System.err.println("------------- Read remote file fail ------------------"); e.printStackTrace(); } finally { if (is != null) { try { is.close(); } catch (IOException e) { System.err.println("------------- Close input stream fail ------------------"); } } if (os != null) { try { os.close(); } catch (IOException e) { System.err.println("------------- Close output stream fail ------------------"); } } } return null; } public static File readFromSmb(String smbMachine, String localpath) { File localfile = null; InputStream bis = null; OutputStream bos = null; try { SmbFile rmifile = new SmbFile(smbMachine); String filename = rmifile.getName(); bis = new BufferedInputStream(new SmbFileInputStream(rmifile)); localfile = new File(localpath + File.separator + filename); bos = new BufferedOutputStream(new FileOutputStream(localfile)); int length = rmifile.getContentLength(); byte[] buffer = new byte[length]; Date date = new Date(); bis.read(buffer); bos.write(buffer); Date end = new Date(); int time = (int) ((end.getTime() - date.getTime()) / 1000); if (time > 0) System.out.println(time + ", " + length / time / 1024); } catch (Exception e) { System.out.println(e.getMessage()); } finally { try { bos.close(); bis.close(); } catch (IOException e) { e.printStackTrace(); } } return localfile; } }
发表评论
-
Linux统计某文件夹下文件、文件夹的个数
2013-07-19 11:27 556转自: http://blog.sina.com.cn/s/b ... -
Linux查看文件创建时间
2013-07-05 14:03 1560查看文件修改时间等:stat fileName 修改文件名:m ... -
Linux查看apache和tomcat是否启动
2013-07-03 17:32 1904查看apache是否启动:ps - ... -
一周学会Linux实践
2013-03-29 17:08 01. Linux 进入图形用户界面:startx或ctrl + ... -
Perl 常用命令汇集
2013-03-25 17:09 0转自: http://www.docin.com/p-5143 ... -
[unix shell笔记] - touch命令
2013-04-25 11:59 611转: http://happyland.blog.51cto. ... -
linux shell wc命令
2013-04-26 09:10 763转自: http://www.cnblogs.com/blog ... -
Linux教程网
2013-03-20 09:56 0http://linux.sheup.com/zhiling. ... -
Linux命令之echo - 显示文本、打印信息
2013-04-26 09:13 659转自: http://codingstandards.itey ... -
linux命令PDF模版课件
2013-03-18 16:05 0转自 http://www.doc88.com/p-38577 ... -
linux rm 命令详解
2013-04-26 09:14 554转自: http://linux.chinaunix.net/ ... -
Shell 条件测试
2013-06-06 10:26 516转自: http://jianlee.ylinux.org/C ... -
linux中 rm -rf和mv有什么区别
2013-06-06 10:26 1095转自: http://zhidao.baidu.com/que ... -
Linux find命令详解
2013-06-06 10:27 675转自: http://linux.chinauni ... -
Linux常用命令积累
2013-04-15 13:17 6101. 切换当前目录到某个文件夹: cd /opt/webhos ... -
Linux添加共享文件夹,windows和Linux间复制粘贴
2013-02-25 13:56 7681. Windows下安装虚拟机VM后,window下的文件不 ... -
Linux下安装jdk和tomcat
2013-02-21 16:39 755参考:http://zhidao.baidu.com/ques ...
相关推荐
Linux与Windows 共享文件Samba
一步一学Linux与Windows_共享文件Samba
linux下samba安装rpm包,其中包含: samba-2.2.7a-7.9.0.i386.rpm, samba-client-2.2.7a-7.9.0.i386.rpm, samba-common-2.2.7a-7.9.0.i386.rpm 全套三个安装包... 已经做好了镜像文件,直接加载即可。
一步一学Linux与Windows 共享文件Samba .doc 一步一学Linux与Windows 共享文件Samba .doc 一步一学Linux与Windows 共享文件Samba .doc 一步一学Linux与Windows 共享文件Samba .doc
linux系统搭建 Samba 服务器,实现windows和linux下文件的共享服务,Samba是著名的开源软件之一,可以实现Windows,Linux/UNIX混合平台的环境中,计算机之间提供文件及打印机等资源的共享服务。使用两种协议,SMB...
linux 文件共享 samba 服务共享
Linux与Windows 共享文件Samba.doc
samba服务实现windows和linux共享文件(绝对可用).pdf
准备共享文件与设置文件访问权限;配置Samba共享配置(1);配置Samba共享配置(2);测试Samba服务器可成功访问;根据要求添加用户;准备共享文件与设置文件访问权限;配置Samba共享配置(1);配置Samba共享配置(2);测试Samba...
为了能够让windows下的用户通过以太网访问Linux下的共享文件,需要开启Samba服务器,本文介绍了Samba服务器的详细配置步骤。
讲述在Linux上如何配置Samba服务器,构建Linux和Windows进行文件共享
1、samba服务器 Windows与Linux文件共享 (主局域网) 1.1samba服务器介绍 1.2samba服务的启动和进程 1.3Samba 配置 1.4samba服务器端常用命令 1.5Samba应用示例一:linux用户在window端访问宿主目录 1.6Samba应用...
samba服务实现windows和linux共享文件(绝对可用)[文].pdf
Linux下的文件共享服务器Samba安装文件及其配置说明 samba-4.14.5.tar
samba安装配置命令 以及linux访问linux文件磁盘
利用Samba实现Linux和Windows文件共享 组建Samba文件服务器.pdf
帮助你快速实现ubuntu下用samba实现windows与linux文件共享,傻瓜化文档,千人验证。
linux设置共享文件,基于Samba的Windows Linux 文件共享方法
SAMBA是一组软件包,使LINUX支持SMB协议,这个协议是在TCP/IP上实现的,它是微软产品之间实现...在linux上安装samba软件包之后,实现如下功能:实现文件与打印机共享、使用linux作登录服务器、使用linux做主域控制器等。